import { useEffect, useRef, useState } from 'react'; import { ChevronDown, ChevronRight } from 'lucide-react'; const sectionId = (title: string) => `report-section-${title.toLowerCase().replace(/[^a-z0-9]+/g, '-')}`; interface ReportSectionProps { title: string; icon: React.ComponentType<{ className?: string }>; children: React.ReactNode; defaultCollapsed?: boolean; } export const ReportSection = ({ title, icon: Icon, children, defaultCollapsed = false, }: ReportSectionProps) => { const [collapsed, setCollapsed] = useState(defaultCollapsed); const ref = useRef(null); useEffect(() => { const el = ref.current; if (!el) return; const handler = () => { setCollapsed(false); el.scrollIntoView({ behavior: 'smooth', block: 'start' }); }; el.addEventListener('report-section-expand', handler); return () => el.removeEventListener('report-section-expand', handler); }, []); return (
{!collapsed &&
{children}
}
); }; export { sectionId };