'use client';

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

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

export default function PrivacyPolicy({ isOpen, onClose }: PrivacyPolicyProps) {
  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 privacy 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">PRIVACY 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>
                This policy covers how we use your personal information. We take your privacy seriously and will take all measures to protect your personal information. Any personal information received will only be used to fulfill your order, and may be used for internal analytical purposes. We will not sell or redistribute your information to anyone.
              </p>
              <p>
                The company shall not be liable for any unforeseeable failure or delay in performance of its obligations under this Agreement arising out of or caused, directly or indirectly, by circumstances beyond its reasonable control, including, without limitation, acts of God.
              </p>
            </div>
          </div>
        </div>
      </div>
    </div>
  );
}

