import { Location } from "@/types"
import { Pencil, Trash2, FileText, Eye, Download } from "lucide-react"
import Link from "next/link"

export function LocationExpandedDetails({
  location,
  onEdit,
  onDelete,
  onDeleteDoc
}: {
  location: Location
  onEdit: () => void
  onDelete: () => void
  onDeleteDoc: () => void
}) {
  const documentName = location.document.trim(
  ).split("/")[5]
  
  return (
    <div className="border-t border-gray-100 bg-gray-50 px-4 py-4">
      {/* Action Buttons */}
      <div className="flex items-center gap-2 mb-4">
        <button
          onClick={onEdit}
          className="flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium border border-gray-200 rounded-lg hover:bg-white transition-colors text-gray-600"
        >
          <Pencil className="w-3 h-3" /> Edit
        </button>
        <button
          onClick={onDelete}
          className="flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium border border-red-100 rounded-lg hover:bg-red-50 transition-colors text-red-500"
        >
          <Trash2 className="w-3 h-3" /> Remove
        </button>
      </div>

      {/* Details Grid */}
      <div className="grid grid-cols-2 gap-x-8 gap-y-4 mb-4">
        <DetailRow label="Location Name" value={location.name} />
        <DetailRow label="Location Type" value={location.locationType} />
        <DetailRow label="Address" value={location.address} full />
        <DetailRow
          label="Lease Start Date"
          value={location.leaseStartDate}
        />
        <DetailRow label="Lease End Date" value={location.leaseEndDate} />
        <DetailRow
          label="Monthly Rent"
          value={`₹${new Intl.NumberFormat("en-IN").format(
            location.monthlyRent,
          )}`}
        />
        <DetailRow
          label="Security Deposit"
          value={`₹${new Intl.NumberFormat("en-IN").format(
            location.securityDeposit,
          )}`}
        />
      </div>

      {/* Documents Section */}
      <div className="border-t border-gray-100 pt-4">
        <p className="text-[10px] font-semibold uppercase tracking-widest text-gray-400 mb-3">
          Lease Document
        </p>
        <div className="grid grid-cols-4 gap-3">
          {/* Document Card */}
          <div className="p-3 bg-white rounded-lg border border-gray-200 hover:border-gray-300 transition-colors">
            <div className="flex items-start justify-between mb-2">
              <div className="w-8 h-8 rounded flex items-center justify-center bg-red-50 flex-shrink-0">
                <FileText className="w-4 h-4 text-red-600" />
              </div>
              {/* Action Buttons - Icons Only */}
              <div className="flex items-center gap-0.5">
                <Link
                  href={location.document}
                  target="__blank"
                  className="p-1.5 rounded hover:bg-gray-100 text-gray-500 hover:text-blue-600 transition-colors"
                  title="View"
                >
                  <Eye className="w-3.5 h-3.5" />
                </Link>
                <Link
                  href={location.document}
                  download={location.document}
                  className="p-1.5 rounded hover:bg-gray-100 text-gray-500 hover:text-green-600 transition-colors"
                  title="Download"
                >
                  <Download className="w-3.5 h-3.5" />
                </Link>
                <button
                  onClick={onDeleteDoc}
                  className="p-1.5 rounded hover:bg-gray-100 text-gray-500 hover:text-red-600 transition-colors"
                  title="Delete"
                >
                  <Trash2 className="w-3.5 h-3.5" />
                </button>
              </div>
            </div>
            <p className="text-xs font-medium text-gray-900 truncate">
              {documentName}
            </p>
            <p className="text-[10px] text-gray-500 mt-1">PDF</p>
          </div>
        </div>
      </div>
    </div>
  )
}

function DetailRow({
  label,
  value,
  full,
}: {
  label: string
  value: string
  full?: boolean
}) {
  return (
    <div className={full ? "col-span-2" : ""}>
      <p className="text-[10px] font-semibold uppercase tracking-widest text-gray-400 mb-0.5">
        {label}
      </p>
      <p className="text-xs text-gray-700 leading-relaxed">{value}</p>
    </div>
  )
}
