'use client';

import React from 'react';
import { X, Check, Sparkles } from 'lucide-react';
import { useMessages } from '@/i18n/client';

interface PricingModalProps {
  isOpen: boolean;
  onClose: () => void;
  onSelectPlan: (plan: 'free' | 'premium') => void;
}

export const PricingModal: React.FC<PricingModalProps> = ({ isOpen, onClose, onSelectPlan }) => {
  const m = useMessages().modals;
  const t = m.pricing;
  if (!isOpen) return null;

  return (
    <div className="fixed inset-0 z-50 flex items-start justify-center p-4 bg-black/80 backdrop-blur-md animate-fade-in overflow-y-auto">
      <div className="relative w-full max-w-4xl bg-white rounded-3xl overflow-hidden shadow-2xl text-slate-900 my-auto">
        <button
          onClick={onClose}
          aria-label={m.close}
          className="absolute top-5 right-5 z-20 w-10 h-10 rounded-full bg-slate-100 hover:bg-slate-200 text-slate-700 flex items-center justify-center transition-colors"
        >
          <X className="w-5 h-5" />
        </button>

        <div className="p-8 sm:p-12">
          <div className="text-center max-w-xl mx-auto mb-12 space-y-3">
            <span className="text-[11px] font-bold tracking-widest text-[#4C7DFF] uppercase">{t.eyebrow}</span>
            <h3 className="text-3xl font-bold tracking-tight text-slate-900">{t.title}</h3>
            <p className="text-slate-500 text-sm">{t.text}</p>
          </div>

          <div className="grid grid-cols-1 md:grid-cols-2 gap-8 items-stretch">
            {/* Free plan */}
            <div className="p-8 rounded-3xl border border-slate-200 bg-slate-50/50 flex flex-col justify-between">
              <div className="space-y-4">
                <div>
                  <h4 className="text-xl font-bold text-slate-900">{t.freeTitle}</h4>
                  <p className="text-xs text-slate-500 mt-1">{t.freeText}</p>
                </div>
                <div className="text-3xl font-extrabold text-slate-900">
                  {t.priceFree} <span className="text-xs font-normal text-slate-500">{t.forever}</span>
                </div>
                <ul className="space-y-3 pt-4 border-t border-slate-200 text-sm text-slate-600">
                  {t.freeFeatures.map((f) => (
                    <li key={f} className="flex items-center gap-3">
                      <Check className="w-4 h-4 text-emerald-500 shrink-0" />
                      <span>{f}</span>
                    </li>
                  ))}
                </ul>
              </div>
              <button
                onClick={() => {
                  onClose();
                  onSelectPlan('free');
                }}
                className="mt-8 w-full py-3.5 rounded-full border border-slate-300 font-semibold text-sm hover:bg-slate-100 transition-colors"
              >
                {t.freeCta}
              </button>
            </div>

            {/* Premium plan */}
            <div className="p-8 rounded-3xl border-2 border-[#4C7DFF] bg-[#07111F] text-white flex flex-col justify-between relative shadow-xl">
              <div className="absolute -top-3.5 left-1/2 -translate-x-1/2 px-4 py-1 rounded-full bg-[#4C7DFF] text-white text-[11px] font-bold tracking-wide uppercase shadow-md flex items-center gap-1.5">
                <Sparkles className="w-3.5 h-3.5" />
                <span>{t.recommended}</span>
              </div>
              <div className="space-y-4">
                <div>
                  <h4 className="text-xl font-bold text-white">{t.premiumTitle}</h4>
                  <p className="text-xs text-slate-400 mt-1">{t.premiumText}</p>
                </div>
                <div className="text-3xl font-extrabold text-white">
                  {t.pricePremium} <span className="text-xs font-normal text-slate-400">{t.once}</span>
                </div>
                <ul className="space-y-3 pt-4 border-t border-white/10 text-sm text-slate-300">
                  {t.premiumFeatures.map((f) => (
                    <li key={f} className="flex items-center gap-3">
                      <Check className="w-4 h-4 text-[#4C7DFF] shrink-0" />
                      <span>{f}</span>
                    </li>
                  ))}
                </ul>
              </div>
              <button
                onClick={() => {
                  onClose();
                  onSelectPlan('premium');
                }}
                className="mt-8 w-full py-3.5 rounded-full bg-white text-[#07111F] font-bold text-sm hover:bg-slate-100 transition-colors shadow-lg"
              >
                {t.premiumCta}
              </button>
            </div>
          </div>
        </div>
      </div>
    </div>
  );
};
