"use client" import { ResourcePage } from "@/shared/data-view/resource-page" import { ColumnHeader } from "@/shared/data-view/table-view" import FormDialog from "@/shared/components/form-dialog" import { PayrollRunForm } from "@/modules/payroll/payroll-run-form" import { PAYROLL_ROUTES } from "@garage/api" import type { PayrollClient } from "@garage/api" import { Badge } from "@/shared/components/ui/badge" import { useRouter } from "next/navigation" import { formatEnum } from "@/shared/utils/formatters" type RunRow = { id: number reference?: string | null period_start?: string period_end?: string status: string entries_count?: number generated_at?: string | null finalized_at?: string | null paid_at?: string | null } function formatDate(value: unknown) { if (!value || typeof value !== "string") return "—" const d = new Date(value) return Number.isNaN(d.getTime()) ? value : d.toLocaleDateString() } function statusVariant(status: string): "default" | "secondary" | "outline" { if (status === "paid") return "default" if (status === "finalized") return "outline" return "secondary" } export default function PayrollPage() { const router = useRouter() return ( pageTitle="Payroll" routeKey={PAYROLL_ROUTES.RUNS_INDEX} getClient={(api) => api.payroll} statusFilter={{ statuses: ["draft", "finalized", "paid"], paramKey: "status", }} onRowClick={(row) => router.push(`/productivity/payroll/${(row as any).id}`)} headerProps={({ invalidateQuery }) => ({ actions: ( {() => ( { invalidateQuery() if (runId) router.push(`/productivity/payroll/${runId}`) }} /> )} ), })} columns={({ actionsColumn }) => [ { accessorKey: "reference", header: ({ column }) => , cell: ({ row }) => {(row.original as any).reference ?? `#${(row.original as any).id}`}, }, { accessorKey: "period_start", header: ({ column }) => , cell: ({ row }) => formatDate((row.original as any).period_start), }, { accessorKey: "period_end", header: ({ column }) => , cell: ({ row }) => formatDate((row.original as any).period_end), }, { accessorKey: "entries_count", header: ({ column }) => , cell: ({ row }) => (row.original as any).entries_count ?? "—", }, { accessorKey: "status", header: ({ column }) => , cell: ({ row }) => { const s = (row.original as any).status as string return {formatEnum(s)} }, }, { accessorKey: "finalized_at", header: ({ column }) => , cell: ({ row }) => formatDate((row.original as any).finalized_at), }, actionsColumn({ onEdit: undefined }), ]} /> ) }