import { useTranslation } from "next-i18next/pages"; import { BiCheckCircle, BiError, BiNetworkChart, BiWifi, BiXCircle } from "react-icons/bi"; import { MdSettingsEthernet } from "react-icons/md"; import { SiUbiquiti } from "react-icons/si"; import Container from "../widget/container"; import Error from "../widget/error"; import PrimaryText from "../widget/primary_text"; import Raw from "../widget/raw"; import WidgetIcon from "../widget/widget_icon"; import useWidgetAPI from "utils/proxy/use-widget-api"; export default function Widget({ options }) { const { t } = useTranslation(); const widgetOptions = { ...options, service_group: "unifi_console", service_name: "unifi_console" }; const { data: statsData, error: statsError } = useWidgetAPI(widgetOptions, "stat/sites", { index: options.index }); if (statsError) { return ; } const defaultSite = options.site ? statsData?.data.find((s) => s.desc === options.site) : statsData?.data?.find((s) => s.name === "default"); if (!defaultSite) { return ( {t("unifi.wait")} ); } const getHealth = (subsystem) => { const health = defaultSite.health.find((item) => item.subsystem === subsystem) ?? { status: "unknown" }; return { ...health, up: health.status === "ok", show: health.status !== "unknown" }; }; const wan = getHealth("wan"); const lan = getHealth("lan"); const wlan = getHealth("wlan"); const name = wan.gw_name ?? defaultSite.desc; const uptime = wan["gw_system-stats"] ? wan["gw_system-stats"].uptime : null; const dataEmpty = !(wan.show || lan.show || wlan.show || uptime); return (
{name}
{dataEmpty && (
{t("unifi.empty_data")}
)}
{uptime && (
{t("common.number", { value: uptime / 86400, maximumFractionDigits: 1, })}
{t("unifi.days")}
)} {wan.show && (
{t("unifi.wan")}
{wan.up ? ( ) : ( )}
)} {!wan.show && !lan.show && wlan.show && (
{t("unifi.wlan")}
{wlan.up ? ( ) : ( )}
)} {!wan.show && !wlan.show && lan.show && (
{t("unifi.lan")}
{lan.up ? ( ) : ( )}
)}
{wlan.show && (
{t("common.number", { value: wlan.num_user, maximumFractionDigits: 0, })}
)} {lan.show && (
{t("common.number", { value: lan.num_user, maximumFractionDigits: 0, })}
)} {((wlan.show && !lan.show) || (!wlan.show && lan.show)) && (
{t("common.number", { value: wlan.show ? wlan.num_adopted : lan.num_adopted, maximumFractionDigits: 0, })}
)}
); }