import { useEffect } from "react"; import { useTranslation } from "react-i18next"; import { BarChart3, Table } from "lucide-react"; export type ViewMode = "chart" | "table"; export interface ViewModeToggleProps { value: ViewMode; onChange: (mode: ViewMode) => void; /** localStorage key used to persist the preference per section. */ storageKey?: string; } export function readViewMode(storageKey: string, fallback: ViewMode = "chart"): ViewMode { if (typeof localStorage === "undefined") return fallback; const saved = localStorage.getItem(storageKey); return saved === "chart" || saved === "table" ? saved : fallback; } export default function ViewModeToggle({ value, onChange, storageKey }: ViewModeToggleProps) { const { t } = useTranslation(); useEffect(() => { if (storageKey) localStorage.setItem(storageKey, value); }, [value, storageKey]); const options: { mode: ViewMode; icon: React.ReactNode; label: string }[] = [ { mode: "chart", icon: , label: t("reports.viewMode.chart") }, { mode: "table", icon: , label: t("reports.viewMode.table") }, ]; return (
{options.map(({ mode, icon, label }) => ( ))}
); }