"use client"; import Link from "next/link"; import { useTableControls } from "@/components/ui/use-table-controls"; import { TableControls, SortableTh } from "@/components/ui/table-controls"; import { AddSiteButton, EditSiteButton } from "./site-form"; import { ConfirmDeleteButton } from "@/components/ui/confirm-delete-button"; import { deleteSite } from "./actions"; export type SiteRow = { id: string; code: string; name: string; address: string | null; latitude: number | null; longitude: number | null; isActive: boolean; vesselCount: number; inventoryCount: number; }; const CHIPS = ["Active", "Inactive"]; export function SitesTable({ sites, canEdit, }: { sites: SiteRow[]; canEdit: boolean; }) { const { search, setSearch, sortKey, sortDir, toggleSort, activeFilters, toggleFilter, filtered } = useTableControls({ rows: sites, defaultSortKey: "name", searchText: (s) => [s.code, s.name, s.address ?? "", s.isActive ? "active" : "inactive"].join(" "), chipMatch: (s, chip) => { if (chip.toLowerCase() === "active") return s.isActive; if (chip.toLowerCase() === "inactive") return !s.isActive; return false; }, sortValue: (s, key) => { if (key === "isActive") return s.isActive ? "Active" : "Inactive"; const val = s[key as keyof SiteRow]; if (val === null || val === undefined) return ""; return typeof val === "string" || typeof val === "number" || typeof val === "boolean" ? val : String(val); }, }); return (

Sites

Ports, depots and offices with inventory

{canEdit && }
toggleSort(k as keyof SiteRow)}>Name toggleSort(k as keyof SiteRow)}>Code toggleSort(k as keyof SiteRow)}>Address toggleSort(k as keyof SiteRow)}>Status {canEdit && } {filtered.length === 0 && ( )} {filtered.map((site) => ( {canEdit && ( )} ))}
Cost Centres Items tracked Location
No sites match your search.
{site.name} {site.code} {site.address ?? } {site.vesselCount || } {site.inventoryCount || } {site.latitude && site.longitude ? `${site.latitude.toFixed(4)}, ${site.longitude.toFixed(4)}` : Not set} {site.isActive ? "Active" : "Inactive"}
); }