'use client';

import { useEffect } from 'react';
import { X } from 'lucide-react';
import Image from 'next/image';

interface PaymentPolicyProps {
  isOpen: boolean;
  onClose: () => void;
}

export default function PaymentPolicy({ isOpen, onClose }: PaymentPolicyProps) {
  useEffect(() => {
    if (!isOpen) return;

    const handleEscape = (e: KeyboardEvent) => {
      if (e.key === 'Escape') {
        onClose();
      }
    };

    document.addEventListener('keydown', handleEscape);
    document.body.style.overflow = 'hidden';

    return () => {
      document.removeEventListener('keydown', handleEscape);
      document.body.style.overflow = '';
    };
  }, [isOpen, onClose]);

  if (!isOpen) return null;

  return (
    <div className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/50" onClick={onClose}>
      <div
        className="bg-white w-full max-w-4xl max-h-[90vh] overflow-y-auto relative"
        onClick={(e) => e.stopPropagation()}
      >
        {/* Header */}
        <div className="sticky top-0 bg-white border-b-2 border-black z-10">
          <div className="flex items-center justify-center p-6 relative">
            <div className="flex items-center justify-center gap-4">
              <div className="relative w-32 h-12">
                <Image
                  src="/assets/logos/Untitled-1-02.png"
                  alt="Bakht Apparel"
                  fill
                  className="object-contain"
                  sizes="128px"
                  quality={90}
                />
              </div>
            </div>
            <button
              onClick={onClose}
              className="absolute right-6 p-2 hover:bg-gray-100 rounded-full transition-colors"
              aria-label="Close payment policy"
            >
              <X className="w-6 h-6 text-gray-700" />
            </button>
          </div>
          <div className="bg-black text-white px-6 py-2">
            <h2 className="text-lg font-semibold uppercase tracking-wide text-center">PAYMENT POLICY</h2>
          </div>
        </div>

        {/* Content */}
        <div className="p-6 md:p-8">
          <div className="prose prose-sm max-w-none">
            <div className="space-y-4 text-gray-700 leading-relaxed">
              <p>
                A 50% advance is required to confirm your order, with the remaining 50% due upon completion before delivery.
              </p>
            </div>
          </div>
        </div>
      </div>
    </div>
  );
}

