import { ChevronUp, ChevronRight, Pencil, Trash2 } from "lucide-react"
import Badge from "@/components/ui/badge/badge"
import { GuarantorExpandedDetails } from "./GuarantorExpandedDetails"
import { GuarantorFormValues } from "@/schema/Guarantor"

interface Guarantor extends GuarantorFormValues {
  id: string;
}

interface GuarantorCardProps {
  guarantor: Guarantor
  idx: number
  open: boolean
  toggleExpand: (id: string) => void
  setEditTarget: (guarantor: Guarantor) => void
  handleDelete: (id: string) => void
}

export function GuarantorCard({
  guarantor,
  idx,
  open,
  toggleExpand,
  setEditTarget,
  handleDelete,
}: GuarantorCardProps) {
  return (
  <div className="border border-gray-200 rounded-xl bg-white overflow-hidden group">
  <div className="flex items-center gap-3 px-4 py-3">
    {/* Avatar */}
    <div className="w-10 h-10 rounded-full bg-blue-100 flex items-center justify-center flex-shrink-0">
      <span className="text-sm font-semibold text-blue-700">
        {guarantor.name
          ?.split(" ")
          .map((n) => n[0])
          .join("")
          .slice(0, 2)}
      </span>
    </div>

    {/* Name + Metadata */}
    <div className="flex-1 min-w-0">
      <h3 className="text-sm font-semibold text-gray-900">
        {guarantor.name}
      </h3>

      <div className="flex items-center gap-2 mt-1 flex-wrap">
        <Badge variant="info">
          Guarantor
        </Badge>

        <span className="text-[11px] text-gray-500">
          {guarantor.nationality}
        </span>

        <span className="text-[11px] text-gray-300">•</span>

        <span className="text-[11px] text-gray-500">
          {guarantor.gender}
        </span>
      </div>
    </div>

    {/* Shareholding */}
    <div className="text-right">
      <p className="font-bold text-gray-900 text-sm">
        {guarantor.shareholdingPercentage}%
      </p>
      <p className="text-xs text-gray-500">
        Shareholding
      </p>
    </div>

    {/* Edit / Delete */}
    <div className="flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity">
      <button
        onClick={() => setEditTarget(guarantor)}
        className="p-1.5 rounded-lg text-gray-300 hover:text-blue-600 hover:bg-blue-50 transition-colors"
      >
        <Pencil className="w-3.5 h-3.5" />
      </button>

      <button
        onClick={() => handleDelete(guarantor.id)}
        className="p-1.5 rounded-lg text-gray-300 hover:text-red-500 hover:bg-red-50 transition-colors"
      >
        <Trash2 className="w-3.5 h-3.5" />
      </button>
    </div>

    {/* Expand */}
    <button
      onClick={() => toggleExpand(guarantor.id)}
      className="p-1 rounded-lg text-gray-400 hover:text-gray-600 hover:bg-gray-100 transition-colors"
    >
      {open ? (
        <ChevronUp className="w-4 h-4" />
      ) : (
        <ChevronRight className="w-4 h-4" />
      )}
    </button>
  </div>

  {open && (
    <GuarantorExpandedDetails
      guarantor={guarantor}
      onEdit={() => setEditTarget(guarantor)}
      onDelete={() => handleDelete(guarantor.id)}
    />
  )}
</div>
  )
}
