import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
import { Button } from "@/components/ui/button"
import { formatCurrency, formatDate, formatNumber } from "@/lib/utils"
import { FileText, DollarSign } from "lucide-react"

interface ContractInfoCardProps {
  contract: {
    contractName?: string | null
    createdAt?: Date | string | null
    startDate?: string | null
    endDate?: string | null
    contractDate?: Date | string | null
    purchaseGroup?: string | null
    totalAmount?: number | string | null
    currency?: string | null
    paymentTerms?: string | null
    deliveryTerms?: string | null
  }
}

export function ContractInfoCard({ contract }: ContractInfoCardProps) {
  return (
    <Card>
      <CardHeader>
        <CardTitle className="text-lg">계약조건</CardTitle>
      </CardHeader>
      <CardContent>
        <div className="grid grid-cols-1 md:grid-cols-2 gap-4">
          <div className="space-y-1">
            <p className="text-sm font-medium text-muted-foreground">계약명</p>
            <p className="text-sm">{contract.contractName || "-"}</p>
          </div>
          <div className="space-y-1">
            <p className="text-sm font-medium text-muted-foreground">계약요청일</p>
            <p className="text-sm">
              {formatDate(contract.createdAt)}
            </p>
          </div>
          <div className="space-y-1">
            <p className="text-sm font-medium text-muted-foreground">계약기간</p>
            <p className="text-sm">
              {contract.startDate && contract.endDate
                ? `${formatDate(contract.startDate)} ~ ${formatDate(contract.endDate)}`
                : "-"}
            </p>
          </div>
          <div className="space-y-1">
            <p className="text-sm font-medium text-muted-foreground">계약체결일</p>
            <p className="text-sm">
              {formatDate(contract.contractDate)}
            </p>
          </div>
          <div className="space-y-1">
            <p className="text-sm font-medium text-muted-foreground">SHI 계약담당자</p>
            <p className="text-sm">{contract.purchaseGroup || "-"}</p>
          </div>
          <div className="space-y-1">
            <p className="text-sm font-medium text-muted-foreground">연계입찰/견적번호</p>
            <p className="text-sm">-</p>
          </div>
          <div className="space-y-1">
            <p className="text-sm font-medium text-muted-foreground">계약유효기간</p>
            <p className="text-sm">
              {contract.startDate && contract.endDate
                ? `${formatDate(contract.startDate)} ~ ${formatDate(contract.endDate)}`
                : "-"}
            </p>
          </div>
          <div className="space-y-1">
            <p className="text-sm font-medium text-muted-foreground">계약금액</p>
            <p className="text-sm font-semibold">
              {contract.totalAmount
                ? contract.currency
                  ? formatCurrency(
                      parseFloat(contract.totalAmount.toString()),
                      contract.currency
                    )
                  : formatNumber(parseFloat(contract.totalAmount.toString()))
                : "-"}
            </p>
          </div>
          <div className="space-y-1">
            <p className="text-sm font-medium text-muted-foreground">지불조건</p>
            <p className="text-sm">{contract.paymentTerms || "-"}</p>
          </div>
          <div className="space-y-1">
            <p className="text-sm font-medium text-muted-foreground">인도조건</p>
            <p className="text-sm">{contract.deliveryTerms || "-"}</p>
          </div>
        </div>

        <div className="mt-6 flex gap-2">
          <Button variant="outline" size="sm">
            <FileText className="h-4 w-4 mr-2" />
            계약문서
          </Button>
          <Button variant="outline" size="sm">
            <DollarSign className="h-4 w-4 mr-2" />
            단가상세
          </Button>
        </div>
      </CardContent>
    </Card>
  )
}

