/*
Copyright (C) 2025 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
For commercial licensing, please contact support@quantumnous.com
*/
import React, { useMemo, useState, useRef, useEffect } from "react";
import { Sun, Moon, Monitor } from "lucide-react";
import { useActualTheme } from "../../../context/Theme";
const ThemeToggle = ({ theme, onThemeToggle, t }) => {
const actualTheme = useActualTheme();
const [open, setOpen] = useState(false);
const ref = useRef(null);
const themeOptions = useMemo(
() => [
{
key: "light",
icon: ,
label: t("浅色模式"),
},
{
key: "dark",
icon: ,
label: t("深色模式"),
},
{
key: "auto",
icon: ,
label: t("自动模式"),
},
],
[t],
);
const currentIcon = useMemo(() => {
const opt = themeOptions.find((o) => o.key === theme);
return opt?.icon || themeOptions[2].icon;
}, [theme, themeOptions]);
// Close on outside click
useEffect(() => {
if (!open) return;
const handler = (e) => {
if (ref.current && !ref.current.contains(e.target)) setOpen(false);
};
document.addEventListener("mousedown", handler);
return () => document.removeEventListener("mousedown", handler);
}, [open]);
return (