import { useTranslation } from "next-i18next";
import Container from "components/services/widget/container";
import Block from "components/services/widget/block";
import useWidgetAPI from "utils/proxy/use-widget-api";
export default function Component({ service }) {
const { t } = useTranslation();
const { widget } = service;
const { data: statsData, error: statsError } = useWidgetAPI(widget, "stat/sites");
if (statsError) {
return ;
}
const defaultSite = widget.site
? statsData?.data.find((s) => s.desc === widget.site)
: statsData?.data?.find((s) => s.name === "default");
if (!defaultSite) {
if (widget.site) {
return ;
}
return (
);
}
const wan = defaultSite.health.find((h) => h.subsystem === "wan");
const lan = defaultSite.health.find((h) => h.subsystem === "lan");
const wlan = defaultSite.health.find((h) => h.subsystem === "wlan");
[wan, lan, wlan].forEach((s) => {
s.up = s.status === "ok"; // eslint-disable-line no-param-reassign
s.show = s.status !== "unknown"; // eslint-disable-line no-param-reassign
});
const uptime = wan["gw_system-stats"]
? `${t("common.number", { value: wan["gw_system-stats"].uptime / 86400, maximumFractionDigits: 1 })} ${t(
"unifi.days",
)}`
: null;
if (!(wan.show || lan.show || wlan.show || uptime)) {
return (
);
}
return (
{uptime && }
{wan.show && }
{lan.show && }
{lan.show && !wlan.show && (
)}
{lan.show && !wlan.show && }
{wlan.show && }
{wlan.show && !lan.show && (
)}
{wlan.show && !lan.show && }
);
}