'use client';

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

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

export default function ShippingPolicy({ isOpen, onClose }: ShippingPolicyProps) {
  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 shipping 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">SHIPPING 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>
                Our shipping timing for orders DELIVERY varies for different products and categories. It will be informed on order confirmation, any delays will be informed accordingly, There can be unexpected delivery delays due to custom clearance or may be any undefined reason. The delay can further go up to 5-6 working days or more. We are not responsible for any kind of delays.
              </p>
            </div>
          </div>
        </div>
      </div>
    </div>
  );
}

