'use client';

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

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

export default function ExchangeReturnPolicy({ isOpen, onClose }: ExchangeReturnPolicyProps) {
  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 exchange and return 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">EXCHANGE AND RETURN 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>
                There is no exchange policy as per customer's liking or disliking of the product since all outfits are made to order for our esteemed customers.
              </p>
              <p>
                An exchange will only occur in the unlikely situation that we have sent you a defective or incorrect item, and only in the even the purchased goods is unused and undamaged by the customer.
              </p>
              <p>
                If you find the product faulty you have to get back to us within 48 hours of delivery. After you generate a query, the Quality department of the company will look into the issue and get right back to you. After reviewing the product, we may offer you an exchange or store credit for future purchases in case of any major fault.
              </p>
              <p>
                Moreover, orders those are customized or given a discount on are not eligible for Return, Refund or Chargeback
              </p>
            </div>
          </div>
        </div>
      </div>
    </div>
  );
}

