"use client";
import { ChevronDown } from "lucide-react";
import { useState, type ReactNode } from "react";
import { fmtInt } from "@/lib/format";
import { cn } from "./cn";
/** Rows kept visible while collapsed (matches `.dci-collapse` nth-child rule in globals.css). */
export const COLLAPSE_ROWS = 10;
/**
* Mobile-only "Show all N" for long server-rendered lists (tables,
/
): under 640 px only the
* first COLLAPSE_ROWS rows are shown until the user expands. Purely CSS-driven (data attribute), so the
* children stay server components and nothing but serialisable props crosses the boundary.
* On ≥ 640 px every row is visible and the toggle is hidden.
*/
export function CollapsibleRows({ total, label = "rows", children, className }: { total: number; label?: string; children: ReactNode; className?: string }) {
const [open, setOpen] = useState(false);
const collapsible = total > COLLAPSE_ROWS + 2;
const collapsed = collapsible && !open;
return (