import useSWR from "swr";
import { BiError } from "react-icons/bi";
import { FaMemory, FaRegClock, FaThermometerHalf } from "react-icons/fa";
import { FiCpu } from "react-icons/fi";
import { useTranslation } from "next-i18next";
import UsageBar from "../resources/usage-bar";
export default function Widget({ options }) {
const { t, i18n } = useTranslation();
const { data, error } = useSWR(
`/api/widgets/glances?${new URLSearchParams({ lang: i18n.language, ...options }).toString()}`, {
refreshInterval: 1500,
}
);
if (error || data?.error) {
return (
);
}
if (!data) {
return (
{options.label && (
{options.label}
)}
);
}
const unit = options.units === "imperial" ? "fahrenheit" : "celsius";
const mainTemp = (options.cputemp && data.sensors && unit === "celsius") ? data.sensors.find(s => s.label.includes("cpu_thermal")).value : data.sensors.find(s => s.label.includes("cpu_thermal")).value * 5/9 + 32;
return (
{t("common.number", {
value: data.quicklook.cpu,
style: "unit",
unit: "percent",
maximumFractionDigits: 0,
})}
{t("glances.cpu")}
{t("common.number", {
value: data.quicklook.mem,
style: "unit",
unit: "percent",
maximumFractionDigits: 0,
})}
{t("glances.mem")}
{options.cputemp &&
(
{t("common.number", {
value: mainTemp,
maximumFractionDigits: 1,
style: "unit",
unit
})}
{t("glances.temp")}
)}
{options.uptime && data.uptime &&
(
{data.uptime.replace(" days,", t("glances.days")).replace(/:\d\d:\d\d$/g, t("glances.hours"))}
{t("glances.uptime")}
)}
{options.label && (
{options.label}
)}
);
}