"use client"; import React from "react"; import { TableList, TableListProps } from "./TableList"; import { useLocal } from "@/lib/utils/use-local"; import get from "lodash.get"; import { TabHeaderBetter } from "../tablist/TabHeaderBetter"; import { getNumber } from "@/lib/utils/getNumber"; import { BreadcrumbBetterLink } from "../ui/breadcrumb-link"; export interface TableUIProps extends TableListProps { tabHeader?: ((local: any) => React.ReactNode) | React.ReactNode; modeTab?: "default" | "only-title"; tab?: { id: string; name: string; count?: number | null }[]; // ✅ Update count menjadi nullable onTab?: (tabId: any) => void; breadcrumb?: { title?: string; label?: string; url?: string }[]; title?: string; ready?: boolean; } export const TableUI = ({ tabHeader, name, modeTab, column, align = "center", onLoad, take = 20, header, disabledPagination, disabledHeader, disabledHeadTable, hiddenNoRow, disabledHoverRow, onInit, onCount, fm, mode = "table", feature, onChange, tab, onTab, breadcrumb, title, ready = true, filter = true, }: TableUIProps) => { const local = useLocal({ tab: get(tab, "[0].id"), table: null as any, show: true as boolean, }); if (!ready) { return (
); } return (
{title}
{breadcrumb?.length ? ( ) : ( <> )}
{tab?.length && (
{ return (
{modeTab !== "only-title" ? (
{getNumber(row?.count) > 999 ? "99+" : getNumber(row?.count)}
) : ( <> )}
{modeTab !== "only-title" ? (
Total
) : ( <> )}
{row.name}
); }} onValue={(row: any) => { return row.id; }} onLoad={tab} onChange={(tab: any) => { local.tab = tab?.id; local.render(); if (typeof onTab === "function") { onTab(local.tab); } local.show = false; local.render(); setTimeout(() => { local.show = true; local.render(); }, 100); if (typeof local?.table?.refresh === "function") { { local.table.refresh(); } } }} tabContent={(data: any) => { return <>; }} />
)}
{tab?.length ? ( typeof tabHeader === "function" ? ( tabHeader(local) ) : ( tabHeader ) ) : ( <> )}
{local.show ? ( { local.table = e; local.render(); if (typeof onInit === "function") { onInit(e); } }} /> ) : ( <> )}
); };