"use client"
import {
Calendar,
Hash,
Building2,
AlertTriangle,
CheckCircle2,
TimerIcon,
ReceiptIcon,
Wrench,
Tag,
Percent,
} from "lucide-react"
import {
Card,
CardContent,
CardHeader,
CardTitle,
} from "@/shared/components/ui/card"
import { Badge } from "@/shared/components/ui/badge"
import { cn } from "@/shared/lib/utils"
import { formatDate, formatCurrency, formatEnum } from "@/shared/utils/formatters"
import { getFullName } from "@/shared/utils/getFullName"
import { useExpense } from "./expense-context"
function InfoItem({
icon: Icon,
label,
value,
}: {
icon: React.ComponentType<{ className?: string }>
label: string
value?: string | null
}) {
return (
)
}
const statusVariantMap: Record = {
draft: "secondary",
open: "default",
un_paid: "destructive",
partially_paid: "secondary",
paid: "default",
cancelled: "destructive",
}
export function ExpenseGeneralInfo() {
const expense = useExpense()
if (!expense) return null
const vendor = expense.vendor || {}
const department = expense.department || null
const jobCard = expense.job_card || null
const category = expense.category || null
const labels = (expense as any)?.labels || []
const balanceDue = expense.balance_due ?? null
const paymentsM = expense.payments_made ?? null
const taxLabel = expense.tax?.title
? `${expense.tax.title} (${expense.tax.rate}%)`
: "Tax"
return (
{/* ── Summary Hero ── */}
{/* Status */}
Status
{expense.status === "paid" &&
}
{expense.status === "pending" &&
}
{expense.status === "open" &&
}
{expense.status === "un_paid" &&
}
{formatEnum(String(expense.status ?? ""))}
{/* Total */}
Total
{formatCurrency(expense.total ?? 0)}
{expense.sub_total != null && expense.sub_total !== expense.total && (
Subtotal: {formatCurrency(expense.sub_total)}
)}
{/* Payments Made */}
Paid
{formatCurrency(paymentsM ?? 0)}
{/* Balance Due */}
0 && "border-destructive/50 bg-destructive/5")}>
Balance Due
0 ? "text-destructive" : "text-green-600 dark:text-green-400")}>
{formatCurrency(balanceDue ?? 0)}
{/* ── Vendor ── */}
Vendor
{vendor.company_name || getFullName(vendor as any) || "—"}
{/* ── Expense Details ── */}
Expense Details
{expense.discount && expense.discount !== "no" && (
)}
{expense.discount_amount_major != null && expense.discount_amount_major > 0 && (
)}
{expense.tax_amount != null && expense.tax_amount > 0 && (
)}
{/* ── Job Card & Category ── */}
{(jobCard || category) && (
Related Information
{jobCard && (
Job Card
{jobCard.order_number || "—"}
{jobCard.title || ""}
)}
{category && (
Category
{category.title || "—"}
)}
)}
{/* ── Labels ── */}
{labels && labels.length > 0 && (
Labels
{labels.map((label: any) => (
{label.title}
))}
)}
{/* ── Notes ── */}
{expense.notes && (
Notes
{expense.notes}
)}
)
}