import { useEffect } from "preact/hooks";
import { signal } from "@preact/signals";
const themes = signal([]); const current = signal("");
let mod = null;
export function ThemeCard() {
useEffect(() => {
const themesUrl = new URL("/static/themes.js", location.origin).href;
import( themesUrl)
.then((m) => {
mod = m;
themes.value = m.THEMES.map((t) => ({ id: 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 (
<section class="settings-card" id="theme-picker">
<h2>Theme</h2>
<p class="settings-lede">
Sets the editor theme, terminal palette and reader palette together. All
bundles are muted, low-contrast — picked for a phone screen at night.
Switching applies live to any open terminal tab.
</p>
<label class="settings-row">
<span class="settings-label">
<strong>Colour theme</strong>
<small>
Stored locally as <code>mobux:theme</code>. Per-device.
</small>
</span>
<select
class="settings-select"
value={current.value}
onChange={onChange}
>
{themes.value.map((t) => (
<option key={t.id} value={t.id}>
{t.label}
</option>
))}
</select>
</label>
</section>
);
}