import Block from "components/services/widget/block";
import Container from "components/services/widget/container";
import { useTranslation } from "next-i18next";
import useWidgetAPI from "utils/proxy/use-widget-api";
const UNRAID_DEFAULT_FIELDS = ["status", "cpu", "memoryPercent", "notifications"];
const MAX_ALLOWED_FIELDS = 4;
const POOLS = ["pool1", "pool2", "pool3", "pool4"];
const POOL_FIELDS = [
{ param: "UsedSpace", label: "poolUsed", valueKey: "fsUsed", valueType: "common.bytes" },
{ param: "FreeSpace", label: "poolFree", valueKey: "fsFree", valueType: "common.bytes" },
{ param: "UsedPercent", label: "poolUsed", valueKey: "fsUsedPercent", valueType: "common.percent" },
];
export default function Component({ service }) {
const { t } = useTranslation();
const { widget } = service;
const { data, error } = useWidgetAPI(widget);
if (error) {
return ;
}
if (!widget.fields?.length) {
widget.fields = UNRAID_DEFAULT_FIELDS;
} else if (widget.fields.length > MAX_ALLOWED_FIELDS) {
widget.fields = widget.fields.slice(0, MAX_ALLOWED_FIELDS);
}
if (!data) {
return (
{...POOLS.flatMap((pool) =>
POOL_FIELDS.map(({ param, label }) => (
)),
)}
);
}
return (
{...POOLS.flatMap((pool) =>
POOL_FIELDS.map(({ param, label, valueKey, valueType }) => {
const poolValue = data.caches?.[widget?.[pool]]?.[valueKey] || "-";
return (
);
}),
)}
);
}