"use client"; /** * Catalog detail-pane previews — compose real DS components (no bespoke stand-ins). */ import * as React from "react"; import { Bar, BarChart, CartesianGrid, XAxis, YAxis } from "recharts"; import { ChartCard, ChartLeoPlotInsightOverlay, type ChartCardVariant, } from "@/components/charts-core"; import { CATALOG_PREVIEW_CHART_LEO } from "@/lib/catalog-preview-chart-leo"; import { KeyMetrics, type MetricItem } from "@/components/key-metrics"; import { LibraryBoardCard, LibraryBoardView, LibraryListRowCard, } from "@/components/library-board-view"; import { buildLibraryHubColumnDefs } from "@/components/library-table"; import { PageHeader } from "@/components/page-header"; import { Button } from "@/components/ui/button"; import { ColumnTypesRuleDemoTable } from "@/components/column-types-rule-demo-client"; import { DataTable, withRowDragColumn } from "@/components/data-table"; import { DataTablePaginated } from "@/components/data-table/pagination"; import { PageScrollNav } from "@/components/ui/page-scroll-nav"; import { useLeoGeneration, useLeoGenerationGroup } from "@exxatdesignux/ui/lib/leo-generation"; import { LeoGenerationSection } from "@exxatdesignux/ui/components/ui/leo-generation-surface"; import { useTableState } from "@/components/data-table/use-table-state"; import type { ColumnDef } from "@/components/data-table/types"; import { HubTable } from "@/components/data-views"; import { ChartContainer, ChartTooltip, ChartTooltipContent, } from "@/components/ui/chart"; import { ViewSegmentedControl } from "@/components/ui/view-segmented-control"; import { CHART_AXIS_TICK } from "@/lib/chart-typography"; import { toggleLibraryItemFavorite } from "@/lib/library-nav"; import { LIBRARY_ITEMS, type LibraryItem } from "@/lib/mock/library"; import { cn } from "@/lib/utils"; const CATALOG_LIBRARY_ROWS: LibraryItem[] = LIBRARY_ITEMS.slice(0, 9); const CATALOG_METRICS: MetricItem[] = [ { id: "published", label: "Published", value: 128, delta: "+6", trend: "up", trendPolarity: "higher_is_better", href: "#published", chart: { kind: "sparkline", series: [ { value: 98, label: "Jan" }, { value: 104, label: "Feb" }, { value: 110, label: "Mar" }, { value: 116, label: "Apr" }, { value: 122, label: "May" }, { value: 128, label: "Jun" }, ], }, }, { id: "draft", label: "Draft", value: 14, delta: "-2", trend: "down", trendPolarity: "higher_is_better", href: "#draft", chart: { kind: "bars", tone: "info", series: [ { value: 18, label: "Mon" }, { value: 16, label: "Tue" }, { value: 15, label: "Wed" }, { value: 17, label: "Thu" }, { value: 14, label: "Fri" }, { value: 14, label: "Sat" }, { value: 14, label: "Sun" }, ], }, }, { id: "review", label: "In review", value: 9, delta: "", trend: "neutral", trendPolarity: "informational", href: "#review", progress: 45, }, { id: "flags", label: "Review flags", value: 2, delta: "+1", trend: "up", trendPolarity: "lower_is_better", href: "#flags", alert: "danger", chart: { kind: "sparkline", tone: "danger", series: [ { value: 1, label: "Week 1" }, { value: 0, label: "Week 2" }, { value: 1, label: "Week 3" }, { value: 1, label: "Week 4" }, { value: 2, label: "Week 5" }, ], }, }, ]; const CATALOG_CHART_DATA = [ { month: "Jan", placements: 42 }, { month: "Feb", placements: 58 }, { month: "Mar", placements: 74 }, { month: "Apr", placements: 68 }, { month: "May", placements: 81 }, ]; const catalogChartConfig = { placements: { label: "Placements", color: "var(--brand-color)" }, } as const; const CATALOG_CHART_FILTER_OPTIONS = [ { value: "30d", label: "Last 30 days" }, { value: "90d", label: "Last quarter" }, { value: "1y", label: "Last year" }, ]; const CATALOG_CHART_VARIANT_OPTIONS: { value: ChartCardVariant; label: string; icon: string; }[] = [ { value: "normal", label: "Normal", icon: "fa-light fa-chart-column" }, { value: "tabs", label: "Tabs", icon: "fa-light fa-table-columns" }, { value: "selector", label: "Selector", icon: "fa-light fa-filter" }, { value: "metrics-tabs", label: "Metrics", icon: "fa-light fa-gauge-high" }, { value: "kpi-chart", label: "KPI", icon: "fa-light fa-hashtag" }, ]; function CatalogMiniBarChart() { return (
} />
); } const CATALOG_CHART_MINI_METRICS = [ { label: "Placements", value: "128", trend: "up" as const, trendPolarity: "higher_is_better" as const, }, { label: "Applications", value: "214", trend: "up" as const, trendPolarity: "informational" as const, }, { label: "Reviews", value: "42", trend: "neutral" as const, trendPolarity: "informational" as const, }, ]; export function CatalogChartCardVariantPreview({ variant, className, }: { variant: ChartCardVariant; className?: string; }) { const needsMiniMetrics = variant === "metrics-tabs" || variant === "kpi-chart"; const needsSelectorFilter = variant === "selector"; return ( ); } export function CatalogChartCardPreview({ className }: { className?: string }) { const [variant, setVariant] = React.useState("metrics-tabs"); return (
setVariant(v as ChartCardVariant)} aria-label="ChartCard variant" options={CATALOG_CHART_VARIANT_OPTIONS} />
); } export function CatalogKeyMetricsPreview({ className, }: { className?: string; }) { const [variant, setVariant] = React.useState<"cards" | "card" | "flat">( "cards", ); const [size, setSize] = React.useState<"sm" | "md" | "lg">("md"); return (
); } export function CatalogPageHeaderPreview() { return ( New record } /> ); } export function CatalogBoardCardPreview() { return ( {}} /> ); } export function CatalogLibraryListRowPreview() { return ( {}} /> ); } function CatalogLibraryHubTablePreview({ rows, onRowsChange, }: { rows: LibraryItem[]; onRowsChange: React.Dispatch>; }) { const toggleFavorite = React.useCallback( (row: LibraryItem) => { onRowsChange((prev) => prev.map((item) => item.id === row.id ? toggleLibraryItemFavorite(item) : item, ), ); }, [onRowsChange], ); const columns = React.useMemo( () => buildLibraryHubColumnDefs(rows, toggleFavorite), [rows, toggleFavorite], ); return (
rows={rows} columns={columns} view="table" hubLabel="Question bank" lifecycleTabLabel="All questions" searchAriaLabel="Search questions" getRowId={(row) => row.id} getRowSelectionLabel={(row) => row.stem} defaultSort={{ key: "stem", dir: "asc" }} emptyState="No questions." renderers={{}} supportedViewTypes={["table"]} persistKey="catalog-preview:library-hub-table" pagination={false} />
); } export function CatalogLibraryHubLivePreview({ className, }: { className?: string; }) { const [view, setView] = React.useState<"table" | "board">("board"); const [rows, setRows] = React.useState(CATALOG_LIBRARY_ROWS); const toggleFavorite = React.useCallback((row: LibraryItem) => { setRows((prev) => prev.map((item) => item.id === row.id ? toggleLibraryItemFavorite(item) : item, ), ); }, []); return (
{view === "board" ? (
) : ( )}
); } export function CatalogHubTablePreview({ className }: { className?: string }) { return ( ); } type CatalogGridRow = { id: string; name: string; status: string; updated: string; } & Record; const CATALOG_GRID_ROWS: CatalogGridRow[] = [ { id: "q_101", name: "Diaphragm innervation", status: "Published", updated: "2026-06-01", }, { id: "q_102", name: "Brachial plexus roots", status: "Draft", updated: "2026-06-02", }, { id: "q_103", name: "Cranial nerve functions", status: "In review", updated: "2026-06-03", }, { id: "q_104", name: "Lower limb dermatomes", status: "Published", updated: "2026-06-04", }, { id: "q_105", name: "Spinal cord tracts", status: "Draft", updated: "2026-06-05", }, ]; const CATALOG_GRID_COLUMNS: ColumnDef[] = [ { key: "name", sortable: true, sortKey: "name", label: "Question", width: 280, filter: { type: "text" }, }, { key: "status", sortable: true, sortKey: "status", label: "Status", width: 120, filter: { type: "select", options: [ { value: "Published", label: "Published" }, { value: "Draft", label: "Draft" }, { value: "In review", label: "In review" }, ], }, }, { key: "updated", sortable: true, sortKey: "updated", label: "Updated", width: 120, filter: { type: "date" }, }, ]; /** Core grid only — sort, filters, resize. Hubs wrap this in HubTable (+ Properties, views). */ const CATALOG_PAGED_ROWS: CatalogGridRow[] = Array.from({ length: 27 }, (_, i) => ({ id: `q_${300 + i}`, name: `${["Phrenic", "Vagus", "Facial", "Radial", "Ulnar", "Median", "Femoral"][i % 7]} nerve, case ${i + 1}`, status: ["Published", "Draft", "In review"][i % 3], updated: `2026-06-${String((i % 28) + 1).padStart(2, "0")}`, })); /** Pagination footer: page size, range, and first / previous / next / last. */ export function CatalogPaginatedTablePreview({ className }: { className?: string }) { const columns = React.useMemo(() => CATALOG_GRID_COLUMNS, []); return (

DataTablePaginated adds the footer. Page size resets to page 1, and filters or search recount the pages.

row.id} getRowSelectionLabel={(row) => row.name} pagination={{ pageSize: 5, pageSizeOptions: [5, 10, 25] }} emptyState="No questions match your filters." />
); } /** Bounded demo of PageScrollNav: its own scrollport, six sections. */ export function CatalogPageScrollNavPreview({ className }: { className?: string }) { const scrollRef = React.useRef(null); return (

Scroll the box: Back to top{" "} appears after a short distance, and the rail on the right tracks the current section. Hover or focus the rail to jump.

{["Overview", "Requirements", "Schedule", "Sites", "Compliance", "Sign-off"].map((title) => (

{title}

Placeholder content for {title.toLowerCase()}. It only needs to be long enough to scroll, so the outline and the back-to-top button have something to do.

))}
); } /** Manual row order: drag the grip, press Alt+↑/↓ on it, or use its menu. Inert while sorted. */ export function CatalogRowReorderPreview({ className }: { className?: string }) { const [rows, setRows] = React.useState(CATALOG_GRID_ROWS); const columns = React.useMemo(() => withRowDragColumn(CATALOG_GRID_COLUMNS), []); const state = useTableState(rows, columns); return (

Drag a row by its grip, or focus the grip and press{" "} Alt+↑/ ↓. The grip also opens a Move menu. Sorting or grouping the table pauses reorder.

row.id} getRowSelectionLabel={(row) => row.name} state={state} onRowsReorder={(next) => setRows(next)} emptyState="No questions match your filters." />
); } /** What Leo "creates" in the demo: a run that adds three rows. */ const CATALOG_LEO_CHILDREN: CatalogGridRow[] = [ { id: "q_201", name: "Phrenic nerve course", status: "Draft", updated: "2026-06-07" }, { id: "q_202", name: "Thoracic duct drainage", status: "In review", updated: "2026-06-07" }, { id: "q_203", name: "Recurrent laryngeal nerve", status: "Draft", updated: "2026-06-07" }, ]; const CATALOG_LEO_CHILD_IDS = CATALOG_LEO_CHILDREN.map((c) => c.id); /** Core grid: a plain DataTable. Leo adding rows is shown on the section example. */ export function CatalogDataTablePreview({ className }: { className?: string }) { const columns = React.useMemo(() => CATALOG_GRID_COLUMNS, []); const state = useTableState(CATALOG_GRID_ROWS, columns, { key: "name", dir: "asc" }); return (

DataTable — the grid primitive. Click a header to sort; drag a header, or focus it and press Alt+←/ → (or use the ⋯ menu), to reorder columns. List hubs compose it via{" "} HubTable (toolbar + Properties + board/list/dashboard).

row.id} getRowSelectionLabel={(row) => row.name} state={state} defaultSort={{ key: "name", dir: "asc" }} emptyState="No questions match your filters." />
); } /** * Parent / child: a SECTION that holds a table. Asking Leo to add data puts * the section in a run (header shows Leo working, Stop) while the table inside * shows its own rows being added one by one. Stop on the section cancels the * whole run; Stop on a row cancels just that row. */ export function CatalogLeoSectionTablePreview({ className }: { className?: string }) { const columns = React.useMemo(() => CATALOG_GRID_COLUMNS, []); const gen = useLeoGenerationGroup(CATALOG_LEO_CHILD_IDS); const gridRows = React.useMemo( () => [ ...CATALOG_GRID_ROWS, ...CATALOG_LEO_CHILDREN.filter((c) => gen.children.find((s) => s.id === c.id)?.delivered), ], [gen.children], ); const state = useTableState(gridRows, columns, { key: "name", dir: "asc" }); const leoRows = React.useMemo( () => gen.children .filter((c) => c.state) .map((c) => ({ id: c.id, state: c.state!, label: `Adding ${CATALOG_LEO_CHILDREN.find((r) => r.id === c.id)?.name}`, onStop: () => gen.stopChild(c.id), })), [gen], ); const created = gen.children.filter((c) => c.delivered).length; const stopped = gen.children.filter((c) => c.stopped).length; return (
{!gen.parent.running && (created > 0 || stopped > 0) ? ( {created} added{stopped > 0 ? `, ${stopped} stopped` : ""}. ) : null}
row.id} getRowSelectionLabel={(row) => row.name} state={state} defaultSort={{ key: "name", dir: "asc" }} emptyState="No questions match your filters." leoLoading={leoRows.length ? { rows: leoRows } : false} />
); } type CatalogSplitRow = { id: string; learner: string; site: string; sessions: string[]; } & Record; const CATALOG_SPLIT_ROWS: CatalogSplitRow[] = [ { id: "s1", learner: "Aarav Mehta", site: "St. Mary's", sessions: ["Mon · Clinic rounds", "Wed · Simulation lab"] }, { id: "s2", learner: "Priya Shah", site: "Riverside", sessions: ["Tue · Ward shift"] }, { id: "s3", learner: "Jordan Lee", site: "Northgate", sessions: ["Mon · Triage", "Thu · Chart review", "Fri · Debrief"] }, ]; const CATALOG_SPLIT_LEO_ROW: CatalogSplitRow = { id: "s4", learner: "Maya Torres", site: "Lakeview", sessions: ["Tue · Clinic rounds", "Thu · Skills check"], }; const CATALOG_SPLIT_COLUMNS: ColumnDef[] = [ { key: "learner", label: "Learner", width: 180 }, { key: "site", label: "Site", width: 140 }, { key: "sessions", label: "Sessions", width: 240, split: { items: (row) => row.sessions }, }, ]; /** * Split row: one record, with Learner and Site once and Sessions stacked as * grouped sub-rows inside the same row. Leo adds a split row too: its loading * row is split the same way, then the real row replaces it. */ export function CatalogSplitRowTablePreview({ className }: { className?: string }) { const gen = useLeoGeneration(); const rows = React.useMemo( () => (gen.delivered ? [...CATALOG_SPLIT_ROWS, CATALOG_SPLIT_LEO_ROW] : CATALOG_SPLIT_ROWS), [gen.delivered], ); const state = useTableState(rows, CATALOG_SPLIT_COLUMNS, { key: "learner", dir: "asc" }); return (
row.id} getRowSelectionLabel={(row) => row.learner} state={state} defaultSort={{ key: "learner", dir: "asc" }} emptyState="No placements." leoLoading={ gen.state ? { rows: [ { id: "leo-split", state: gen.state, label: "Adding Maya Torres", splitCount: 2, onStop: gen.stop, }, ], } : false } />
); } function RowTypeExample>({ title, caption, data, columns, getRowId, leoLoading, }: { title: string; caption: string; data: T[]; columns: ColumnDef[]; getRowId: (row: T) => string; leoLoading?: React.ComponentProps>["leoLoading"]; }) { const state = useTableState(data, columns, undefined); return (

{title}{" "} {caption}

); } /** Every DataTable row type, one or two rows each, in a fixed state. */ export function CatalogRowTypesPreview({ className }: { className?: string }) { const standard = CATALOG_GRID_ROWS.slice(0, 2); const split = CATALOG_SPLIT_ROWS.slice(0, 2); const one = CATALOG_GRID_ROWS.slice(0, 1); const leoRow = (state: "inited" | "thinking" | "completed", label?: string) => ({ rows: [{ id: `leo-${state}`, state, label }], }); return (
r.id} /> r.id} /> r.id} leoLoading={leoRow("inited")} /> r.id} leoLoading={{ rows: [{ id: "leo-thinking", state: "thinking", label: "Adding a question", onStop: () => {} }] }} /> r.id} leoLoading={leoRow("completed")} /> r.id} leoLoading={{ rows: [{ id: "leo-split", state: "thinking", label: "Adding a placement", splitCount: 2, onStop: () => {} }] }} />
); }