import { cycleThemeMode, getThemeMode, onThemeChange } from "../theme"; import { useMemo, useSyncExternalStore } from "react"; import { post } from "../api"; import { fmtRelative, useT, type Key } from "../i18n"; import { navigate } from "../router"; import { useStore } from "../store"; import type { Session } from "../types"; function basename(p: string) { return p.split("/").filter(Boolean).pop() ?? p; } function groupKey(ms: number): Key { const day = 86400000; const startOfToday = new Date().setHours(0, 0, 0, 0); if (ms >= startOfToday) return "sidebar.today"; if (ms >= startOfToday - day) return "sidebar.yesterday"; if (ms >= startOfToday - 7 * day) return "sidebar.week"; return "sidebar.older"; } export function Sidebar({ open, activeId, section }: { open: boolean; activeId?: string; section: string }) { const t = useT(); const sessions = useStore((s) => s.sessions); const busy = useStore((s) => s.busy); const connected = useStore((s) => s.connected); const permissions = useStore((s) => s.permissions); const questions = useStore((s) => s.questions); const me = useStore((s) => s.me); const attention = useMemo(() => { const ids = new Set(); for (const p of permissions) ids.add(p.root_session_id ?? p.session_id); for (const q of questions) ids.add(q.root_session_id ?? q.session_id); return ids; }, [permissions, questions]); const groups = useMemo(() => { const out: { key: Key; items: Session[] }[] = []; for (const s of sessions) { const key = groupKey(s.updated_at); const g = out.find((x) => x.key === key); if (g) g.items.push(s); else out.push({ key, items: [s] }); } return out; }, [sessions]); return ( ); } /** Quick light/dark/auto switcher. */ function ThemeModeButton() { const t = useT(); const mode = useSyncExternalStore(onThemeChange, getThemeMode); const icon = mode === "auto" ? "โ—" : mode === "light" ? "โ˜€" : "โ˜พ"; const label = t(mode === "auto" ? "settings.themeAuto" : mode === "light" ? "settings.themeLight" : "settings.themeDark"); return ( ); }