import { useEffect } from "preact/hooks";
import { signal } from "@preact/signals";
import { u } from "../../lib/base.js";
import { SelectRow } from "./ui.jsx";
const themes = signal([]);
const current = signal("");
let mod = null;
export function ThemeRow() {
useEffect(() => {
const themesUrl = new URL(u("/static/themes.js"), location.origin).href;
import( themesUrl)
.then((m) => {
mod = m;
themes.value = m.THEMES.map((t) => ({ value: t.id, label: t.label }));
current.value = m.getStoredThemeId();
})
.catch((e) => {
themes.value = [];
current.value = "";
console.warn("themes.js load failed", e);
});
}, []);
const onChange = (e) => {
const id = e.target.value;
current.value = id;
if (!mod) return;
mod.setStoredThemeId(id);
mod.applyTheme(id);
window.dispatchEvent(new CustomEvent("mobux:theme", { detail: id }));
};
return (
<SelectRow
rowId="theme-picker"
row="theme"
label="Colour theme"
secondary="Terminal, reader and editor"
value={current.value}
options={themes.value}
onChange={onChange}
/>
);
}