"use client" import { useRouter } from "next/navigation" import FormDialog from "@/shared/components/form-dialog" import { Badge } from "@/shared/components/ui/badge" import { ResourcePage } from "@/shared/data-view/resource-page" import { ColumnHeader } from "@/shared/data-view/table-view" import { BillForm } from "@/modules/bills/bill-form" import { BILL_ROUTES, BillStatus } from "@garage/api" import type { BillsClient } from "@garage/api" import { formatDate, formatEnum } from "@/shared/utils/formatters" import { getFullName } from "@/shared/utils/getFullName" import { Money } from "@/shared/components/money" import { RelationLink } from "@/shared/components/relation-link" import { Building2, Printer } from "lucide-react" import { useDocumentPrint } from "@/shared/hooks/use-document-print" export default function BillsPage() { const router = useRouter() const { print, isPrinting } = useDocumentPrint() return ( pageTitle="Bills" routeKey={BILL_ROUTES.INDEX} searchable searchPlaceholder="Search bills..." statusFilter={{ statuses: BillStatus }} getClient={(api) => api.bills} onRowClick={(row) => router.push(`/purchase/bill/${(row as any).id}`)} headerProps={({ selectedItem, invalidateQuery }) => ({ actions: ( {(resourceId) => ( )} ), })} columns={({ actionsColumn }) => [ { accessorKey: "bill_number", header: ({ column }) => , cell: ({ row }) => (row.original as any).bill_number || "—", }, { accessorKey: "total", header: ({ column }) => , cell: ({ row }) => { const v = (row.original as any).total return v != null && v !== "" ? : "—" }, }, { accessorKey: "balance_due", header: ({ column }) => , cell: ({ row }) => { const v = (row.original as any).balance_due return v != null && v !== "" ? : "—" }, }, { accessorKey: "title", header: ({ column }) => , }, { accessorKey: "vendor", header: ({ column }) => , cell: ({ row }) => { const vendor = (row.original as any).vendor return ( ) }, }, { accessorKey: "bill_date", header: ({ column }) => , cell: ({ row }) => formatDate((row.original as any).bill_date) || "—", }, { accessorKey: "bill_due_date", header: ({ column }) => , cell: ({ row }) => formatDate((row.original as any).bill_due_date) || "—", }, { accessorKey: "status", header: ({ column }) => , cell: ({ row }) => { const status = (row.original as any).status return ( {formatEnum(status)} ) }, }, actionsColumn({ extraItems: (row) => [ { label: isPrinting ? "Printing..." : "Print", icon: Printer, onClick: (r) => print("bill", String(r.id), "print"), }, ], }), ]} /> ) }