"use client"; import { useTableControls } from "@/components/ui/use-table-controls"; import { TableControls, SortableTh } from "@/components/ui/table-controls"; import { AddAccountButton, EditAccountButton } from "./account-form"; import { ConfirmDeleteButton } from "@/components/ui/confirm-delete-button"; import { deleteAccount } from "./actions"; export type AccountRow = { id: string; code: string; name: string; description: string | null; isActive: boolean; }; const CHIPS = ["Active", "Inactive"]; export function AccountsTable({ accounts, suggestedCode, }: { accounts: AccountRow[]; suggestedCode: string; }) { const { search, setSearch, sortKey, sortDir, toggleSort, activeFilters, toggleFilter, filtered } = useTableControls({ rows: accounts, defaultSortKey: "code", searchText: (a) => [a.code, a.name, a.description ?? "", a.isActive ? "active" : "inactive"].join(" "), chipMatch: (a, chip) => { if (chip.toLowerCase() === "active") return a.isActive; if (chip.toLowerCase() === "inactive") return !a.isActive; return false; }, sortValue: (a, key) => { if (key === "isActive") return a.isActive ? "Active" : "Inactive"; const val = a[key as keyof AccountRow]; if (val === null || val === undefined) return ""; return typeof val === "string" || typeof val === "number" || typeof val === "boolean" ? val : String(val); }, }); return (

Account Management

toggleSort(k as keyof AccountRow)}>Code toggleSort(k as keyof AccountRow)}>Name toggleSort(k as keyof AccountRow)}>Description toggleSort(k as keyof AccountRow)}>Status {filtered.length === 0 && ( )} {filtered.map((account) => ( ))}
No accounts match your search.
{account.code} {account.name} {account.description ?? "—"} {account.isActive ? "Active" : "Inactive"}
); }