'use client';

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

export default function DoctorProfileModal({ doctor, onClose }) {
  if (!doctor) return null;

  const fullName = `Dr. ${doctor.firstName} ${doctor.lastName}`;

  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>

        {/* Modal Content */}
        <div className="p-6">
          {/* Header */}
          <div className="mb-4">
            <h2 className="text-2xl font-bold text-gray-800">Doctor Profile</h2>
            <p className="text-gray-500">View and manage personal health information.</p>
          </div>

          {/* Banner Section */}
          <div className="bg-gray-100 rounded-lg overflow-hidden mb-6">
            <div className="relative h-48">
              <Image
                src="/images/doctor-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">{fullName}</h3>
                <p className="text-sm">{doctor.specialization}</p>
              </div>
            </div>
          </div>

          {/* Main Content */}
          <div className="grid grid-cols-1 lg:grid-cols-3 gap-6">
            {/* Sidebar Info */}
            <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">Specializations</h4>
                <p className="text-sm text-gray-700">{doctor.specialization}</p>
              </div>
              <div className="bg-white rounded-xl shadow p-4">
                <h4 className="text-lg font-semibold text-gray-800 mb-2">About</h4>
                <p className="text-sm text-gray-700">{doctor.bio}</p>
              </div>
            </div>

            {/* Personal Info */}
            <div className="lg:col-span-2 bg-white rounded-xl shadow p-6">
              <h4 className="text-lg font-semibold text-gray-800 mb-4">Personal 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">
                  <img
                    src={
                      doctor?.avatar
                        ? doctor.avatar
                        : '/images/patient2.jpg'
                    }
                    alt={`${doctor?.firstName || ''} ${doctor?.lastName || ''}`}
                    width={112}
                    height={112}
                    className="w-28 h-28 rounded-full object-cover shadow-md"
                  />

                </div>
                <div>
                  <p className="font-medium text-gray-600">Full Name</p>
                  <p>{fullName}</p>
                </div>
                {/* <div>
                  <p className="font-medium text-gray-600">Specialization</p>
                  <p>{doctor.specialization}</p>
                </div> */}
                <div>
                  <p className="font-medium text-gray-600">Phone</p>
                  <p>{doctor.phone}</p>
                </div>
                <div>
                  <p className="font-medium text-gray-600">Email</p>
                  <p>{doctor.email}</p>
                </div>
                <div>
                  <p className="font-medium text-gray-600">License Number</p>
                  <p>{doctor.licenceNumber}</p>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  );
}
