import { For, Show, createEffect, createMemo, createSignal, type Component } from "solid-js"; import { cn } from "@/lib/cn"; import { EmptyInline } from "@/components/ui/empty-inline"; import { TablePagination } from "@/components/ui/table-pagination"; import { useT } from "@/stores/preferences-context"; export type ProgressRingSegment = { id: string; label: string; value: number; colorClass: string; }; export type ChartProgressRingProps = { title?: string; subtitle?: string; valueText?: string; subtext?: string; segments: ProgressRingSegment[]; total?: number; class?: string; /** When set and segments.length exceeds it, the legend is paged with Prev/Next controls. */ itemsPerPage?: number; }; export const ChartProgressRing: Component = (props) => { const t = useT(); const [pageIndex, setPageIndex] = createSignal(0); // The gauge bar above always renders every segment's share of the total — // only the legend cards below it are paged. const calculatedTotal = () => props.total ?? props.segments.reduce((acc, s) => acc + s.value, 0); const pageCount = createMemo(() => props.itemsPerPage ? Math.max(1, Math.ceil(props.segments.length / props.itemsPerPage)) : 1, ); createEffect(() => { if (pageIndex() >= pageCount()) setPageIndex(Math.max(0, pageCount() - 1)); }); const visibleSegments = createMemo(() => { if (!props.itemsPerPage) return props.segments; const start = pageIndex() * props.itemsPerPage; return props.segments.slice(start, start + props.itemsPerPage); }); return (

{props.title}

{props.subtitle}

0} fallback={ } >
{/* Total Stat Highlight */}
{props.valueText ?? calculatedTotal()} {props.subtext}
{/* Multi-Segmented Progress Gauge Bar */}
{(segment) => { const pct = () => (calculatedTotal() > 0 ? (segment.value / calculatedTotal()) * 100 : 0); return ( 0}>
); }}
{/* Legend Grid */}
{(segment) => (
{segment.label}
{segment.value}
)}
1}>
); };