import type { RulesEdition } from "@initiative/domain"; import { Monitor, Moon, Sun, X } from "lucide-react"; import { useEffect, useRef } from "react"; import { useRulesEditionContext } from "../contexts/rules-edition-context.js"; import { useThemeContext } from "../contexts/theme-context.js"; import { cn } from "../lib/utils.js"; import { Button } from "./ui/button.js"; interface SettingsModalProps { open: boolean; onClose: () => void; } const EDITION_OPTIONS: { value: RulesEdition; label: string }[] = [ { value: "5e", label: "5e (2014)" }, { value: "5.5e", label: "5.5e (2024)" }, ]; const THEME_OPTIONS: { value: "system" | "light" | "dark"; label: string; icon: typeof Sun; }[] = [ { value: "system", label: "System", icon: Monitor }, { value: "light", label: "Light", icon: Sun }, { value: "dark", label: "Dark", icon: Moon }, ]; export function SettingsModal({ open, onClose }: Readonly) { const dialogRef = useRef(null); const { edition, setEdition } = useRulesEditionContext(); const { preference, setPreference } = useThemeContext(); useEffect(() => { const dialog = dialogRef.current; if (!dialog) return; if (open && !dialog.open) dialog.showModal(); else if (!open && dialog.open) dialog.close(); }, [open]); useEffect(() => { const dialog = dialogRef.current; if (!dialog) return; function handleCancel(e: Event) { e.preventDefault(); onClose(); } function handleBackdropClick(e: MouseEvent) { if (e.target === dialog) onClose(); } dialog.addEventListener("cancel", handleCancel); dialog.addEventListener("mousedown", handleBackdropClick); return () => { dialog.removeEventListener("cancel", handleCancel); dialog.removeEventListener("mousedown", handleBackdropClick); }; }, [onClose]); return (

Settings

Conditions
{EDITION_OPTIONS.map((opt) => ( ))}
Theme
{THEME_OPTIONS.map((opt) => { const Icon = opt.icon; return ( ); })}
); }