2026-05-10 03:06:54 +07:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
|
|
import React from "react";
|
|
|
|
|
import { useUiStore } from "../store/ui-store";
|
2026-05-16 11:50:53 +07:00
|
|
|
import { isDarkTheme } from "../store/ui-store";
|
2026-05-10 03:06:54 +07:00
|
|
|
import { cx, subtleButtonClass } from "../lib/theme";
|
|
|
|
|
import { useTranslations } from "../hooks/use-translations";
|
|
|
|
|
|
|
|
|
|
export function UiPreferences({ compact = false }: { compact?: boolean }) {
|
|
|
|
|
const { theme, locale, setTheme, setLocale } = useUiStore((s) => s);
|
|
|
|
|
const { t } = useTranslations();
|
2026-05-16 11:50:53 +07:00
|
|
|
const isDark = isDarkTheme(theme);
|
2026-05-10 03:06:54 +07:00
|
|
|
const wrapperHeight = compact ? "h-7" : "h-9";
|
|
|
|
|
const textSize = compact ? "text-[10px]" : "text-xs";
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="flex flex-wrap items-center gap-2">
|
|
|
|
|
<label className={cx("inline-flex items-center rounded border px-2", subtleButtonClass(isDark), wrapperHeight)}>
|
|
|
|
|
<span className={cx("mr-2 font-semibold opacity-70", textSize)}>{t("ui.locale")}</span>
|
|
|
|
|
<select
|
|
|
|
|
aria-label={t("ui.locale")}
|
|
|
|
|
value={locale}
|
|
|
|
|
onChange={(event) => setLocale(event.target.value as "en" | "th" | "ja")}
|
|
|
|
|
className={cx(
|
|
|
|
|
"bg-transparent font-semibold outline-none",
|
|
|
|
|
textSize,
|
|
|
|
|
isDark ? "text-[#f5f7fa]" : "text-[#1f2430]",
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
<option value="en">English</option>
|
|
|
|
|
<option value="th">Thai</option>
|
|
|
|
|
<option value="ja">Japanese</option>
|
|
|
|
|
</select>
|
|
|
|
|
</label>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
2026-05-16 11:50:53 +07:00
|
|
|
onClick={() => {
|
|
|
|
|
const next = theme === "light" ? "dark" : theme === "dark" ? "system" : "light";
|
|
|
|
|
setTheme(next);
|
|
|
|
|
}}
|
2026-05-10 03:06:54 +07:00
|
|
|
className={cx("rounded border px-3 font-semibold", subtleButtonClass(isDark), wrapperHeight, textSize)}
|
|
|
|
|
>
|
2026-05-16 11:50:53 +07:00
|
|
|
{theme === "dark" ? t("ui.darkMode") : theme === "system" ? t("ui.systemMode") : t("ui.lightMode")}
|
2026-05-10 03:06:54 +07:00
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|