import { html } from "../html"; const themes = { light: ["latte"], dark: ["frappe", "macchiato", "mocha"], }; const allThemes = [...themes.dark, ...themes.light]; const defaultTheme = "mocha"; function getCurrentTheme(): string { const stored = localStorage.getItem("theme"); if (stored && allThemes.includes(stored)) return stored; return defaultTheme; } function getCurrentBoxyMode(): boolean { const stored = localStorage.getItem("boxyMode"); return stored === "true"; } function applyBoxyMode(isEnabled: boolean) { if (isEnabled) document.documentElement.classList.add("boxy"); else document.documentElement.classList.remove("boxy"); localStorage.setItem("boxyMode", isEnabled.toString()); } function applyTheme(theme: string) { for (const t of allThemes) document.body.classList.remove(`theme-${t}`); document.body.classList.add(`theme-${theme}`); localStorage.setItem("theme", theme); } type DropdownOptionItem = { value: string; label: string; selected?: boolean; }; type DropdownOption = | { type: "optgroup"; name: string; children: DropdownOptionItem[]; } | DropdownOptionItem; type DropdownOptions = { options: DropdownOption[]; selectedValue?: string; onChange: (value: string) => void; label?: string; }; function Dropdown({ options, selectedValue, onChange, label = "select an option", }: DropdownOptions) { const id = `${Math.random().toString(36).substring(2, 15)}`; (window as Window)[`handleDropdownChange_${id}`] = (event: Event) => { const select = event.target as HTMLSelectElement; onChange(select.value); }; const renderOption = (option: DropdownOptionItem) => { const isSelected = selectedValue === option.value; const _ = html` `; return _; }; const renderDropdownOption = (option: DropdownOption) => { if ("type" in option && option.type === "optgroup") { return html` `; } else { return renderOption(option as DropdownOptionItem); } }; return html`