'use client';

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

export default function PharmacyProfileModal({ pharmacy, onClose }) {
  if (!pharmacy) return null;

  return (
    <div
      className="fixed inset-0 bg-white/30 backdrop-blur-sm flex items-center justify-center z-50 px-4"
      onClick={onClose}
    >
      <div
        onClick={(e) => e.stopPropagation()}
        className="bg-white rounded-xl w-full max-w-5xl shadow-2xl relative overflow-y-auto max-h-[90vh] animate-fade-in"
      >
        <button
          onClick={onClose}
          className="absolute top-4 right-4 text-gray-500 hover:text-black"
        >
          <X size={24} />
        </button>

        <div className="p-6">
          <div className="mb-4">
            <h2 className="text-2xl font-bold text-gray-800">Pharmacy Profile</h2>
            <p className="text-gray-500">Detailed information about the pharmacy.</p>
          </div>

          <div className="bg-gray-100 rounded-lg overflow-hidden mb-6">
            <div className="relative h-48">
              <Image
                src="/images/pharmacy-banner.jpg"
                alt="Banner"
                width={1200}
                height={192}
                className="object-cover w-full h-full"
              />
              <div className="absolute bottom-4 left-6 text-white drop-shadow">
                <h3 className="text-xl font-bold">{pharmacy.name}</h3>
                <p className="text-sm">{pharmacy.location}</p>
              </div>
            </div>
          </div>

          <div className="grid grid-cols-1 lg:grid-cols-3 gap-6">
            <div className="space-y-6">
              <div className="bg-white rounded-xl shadow p-4">
                <h4 className="text-lg font-semibold text-gray-800 mb-2">Location</h4>
                <p className="text-sm text-gray-700">{pharmacy.location}</p>
              </div>
              <div className="bg-white rounded-xl shadow p-4">
                <h4 className="text-lg font-semibold text-gray-800 mb-2">Description</h4>
                <p className="text-sm text-gray-700">{pharmacy.description}</p>
              </div>
            </div>

            <div className="lg:col-span-2 bg-white rounded-xl shadow p-6">
              <h4 className="text-lg font-semibold text-gray-800 mb-4">Contact Information</h4>
              <div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4 text-sm text-gray-700">
                <div className="col-span-full mb-4 flex justify-center">
                  <Image
                    src={pharmacy.image}
                    alt="Avatar"
                    width={112}
                    height={112}
                    className="w-28 h-28 rounded-full object-cover shadow-md"
                  />
                </div>
                <div>
                  <p className="font-medium text-gray-600">Phone</p>
                  <p>{pharmacy.phone || '+254-700123456'}</p>
                </div>
                <div>
                  <p className="font-medium text-gray-600">Email</p>
                  <p>{pharmacy.email || 'info@pharmacyexample.com'}</p>
                </div>
                <div>
                  <p className="font-medium text-gray-600">License Number</p>
                  <p>{pharmacy.license || 'PHARM-KE-29383'}</p>
                </div>
                <div>
                  <p className="font-medium text-gray-600">Open Hours</p>
                  <p>{pharmacy.hours || '8am - 10pm daily'}</p>
                </div>
                <div>
                  <p className="font-medium text-gray-600">Services</p>
                  <p>{pharmacy.services || 'Prescriptions, OTC, Delivery'}</p>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>  
    </div>
  );
}
