import { Building, ChevronRight, ChevronUp, MapPin, Pencil, Trash2 } from "lucide-react";
import { PropertyExpandedDetails } from "./PropertyExpandedDetails";
import { Property } from "@/types";

interface PropertyCardProps {
  property: Property;
  open: boolean;
  toggleExpand: (id: string) => void;
  onEdit: (property: Property) => void;
  onDelete: (id: string) => void;
}

export function PropertyCard({ property, open, toggleExpand, onEdit, onDelete }: PropertyCardProps) {
  return (
    <div
      key={property.id}
      className="border border-gray-200 rounded-lg bg-white overflow-hidden"
    >
      {/* Card Row - Compact Header */}
      <div
        onClick={() => toggleExpand(property.id)}
        className="px-4 py-3 flex items-center justify-between hover:bg-gray-50 transition-colors group cursor-pointer"
      >
        {/* Left - Icon + Title + Location */}
        <div className="flex items-center gap-3 flex-1 min-w-0">
          {/* Building Icon with Grey Background */}
          <div className="bg-gray-100 rounded-lg p-2.5 flex-shrink-0">
            <Building size={20} className="text-gray-600" />
          </div>

          {/* Title + Location */}
          <div className="flex-1 min-w-0">
            <h3 className="font-semibold text-gray-900 text-sm truncate">
              {property.propertyAddress}
            </h3>
            <div className="flex items-center gap-1 mt-0.5 truncate">
              <MapPin size={14} className="text-gray-400 flex-shrink-0" />
              <p className="text-xs text-gray-500 truncate">
                {property.ownedBy}
              </p>
            </div>
          </div>
        </div>

        {/* Right - Value + Charge + Actions */}
        <div className="flex items-center gap-4 flex-shrink-0 ml-4">
          {/* Valuation Amount */}
          <div className="text-right">
            <p className="font-bold text-gray-900 text-sm">
              ₹{property.valuationAmount} Cr
            </p>
            <p className="text-xs text-gray-500">Market Value</p>
          </div>

          {/* Charge Type Badge */}
          <span className="px-2.5 py-1 bg-purple-100 text-purple-700 border border-purple-200 rounded text-xs font-medium">
            {property.typeOfCharge?.toUpperCase().replace(/_/g, ' ') || 'HYPOTHECATION'}
          </span>

          {/* Edit / Delete - show on hover */}
          <div className="flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity">
            <button
              onClick={(e) => {
                e.stopPropagation();
                onEdit(property);
              }}
              className="p-1.5 rounded-lg text-gray-300 hover:text-blue-600 hover:bg-blue-50 transition-colors"
              title="Edit"
            >
              <Pencil className="w-3.5 h-3.5" />
            </button>
            <button
              onClick={(e) => {
                e.stopPropagation();
                onDelete(property.id);
              }}
              className="p-1.5 rounded-lg text-gray-300 hover:text-red-500 hover:bg-red-50 transition-colors"
              title="Delete"
            >
              <Trash2 className="w-3.5 h-3.5" />
            </button>
          </div>

          {/* Expand Icon */}
          <div className="p-1 text-gray-400 hover:text-gray-600">
            {open ? (
              <ChevronUp className="w-4 h-4" />
            ) : (
              <ChevronRight className="w-4 h-4" />
            )}
          </div>
        </div>
      </div>

      {/* Expanded Details */}
      {open && (
        <PropertyExpandedDetails 
          property={property}
          onEdit={() => onEdit(property)}
          onDelete={() => onDelete(property.id)}
        />
      )}
    </div>
  );
}
