import React, { useEffect, useState } from 'react'; import { cn } from '@/lib/utils'; import { ChevronDown, ChevronRight } from 'lucide-react'; export function fmt(isoStr) { if (!isoStr) return '—'; const d = new Date(isoStr); return d.toLocaleDateString(undefined, { month: 'short', day: 'numeric', year: 'numeric' }) + ' ' + d.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }); } export function importErrorState(err, fallback) { const data = err?.data || {}; return { message: err?.message || data.message || data.error || fallback, error: data.error || fallback, code: data.code || err?.code || null, details: Array.isArray(data.details) ? data.details : (Array.isArray(err?.details) ? err.details : []), error_id: data.error_id || null, }; } export function SectionCard({ title, subtitle, children, className, collapsible = false, defaultOpen = true, storageKey, summary, actions, }) { const [open, setOpen] = useState(() => { if (!collapsible || !storageKey || typeof window === 'undefined') return defaultOpen; const stored = window.localStorage.getItem(storageKey); return stored === null ? defaultOpen : stored === 'true'; }); useEffect(() => { if (!collapsible || !storageKey || typeof window === 'undefined') return; window.localStorage.setItem(storageKey, String(open)); }, [collapsible, open, storageKey]); const headerContent = ( <> {collapsible && ( open ? : )}

{title}

{subtitle &&

{subtitle}

} {collapsible && !open && summary && (

{summary}

)}
{actions &&
{actions}
} ); return (
{collapsible ? ( ) : (
{headerContent}
)} {open &&
{children}
}
); } export function CountPill({ label, value }) { return (

{label}

{value ?? 0}

); }