"use client"; import { useState } from "react"; import { Center, Divider, Group, Pagination, SegmentedControl, Stack, Text } from "@mantine/core"; import { IconClipboardList, IconCpu2, IconReportAnalytics } from "@tabler/icons-react"; import { clientApi } from "@homarr/api/client"; import { useI18n } from "@homarr/translation/client"; import type { TablerIcon } from "@homarr/ui"; import { views } from "."; import { WidgetEmptyState } from "../common/empty-state"; import type { WidgetComponentProps } from "../definition"; import { HealthCheckStatus } from "./health-check-status"; import { QueuePanel } from "./panels/queue.panel"; import { StatisticsPanel } from "./panels/statistics.panel"; import { WorkersPanel } from "./panels/workers.panel"; type View = (typeof views)[number]; const viewBySegmentValue = Object.fromEntries(views.map((view) => [view, view])) as Record; const viewIcons = { workers: IconCpu2, queue: IconClipboardList, statistics: IconReportAnalytics, } satisfies Record; export default function MediaTranscodingWidget({ integrationIds, options, width, }: WidgetComponentProps<"mediaTranscoding">) { const [queuePage, setQueuePage] = useState(1); const queuePageSize = 10; const input = { integrationId: integrationIds[0] ?? "", pageSize: queuePageSize, page: queuePage, }; const { data: transcodingData } = clientApi.widget.mediaTranscoding.getDataAsync.useQuery(input); const [view, setView] = useState(options.defaultView); const t = useI18n("widget.mediaTranscoding"); if (!transcodingData) return ; const totalQueuePages = Math.ceil((transcodingData.data.queue.totalCount || 1) / queuePageSize); const isTiny = width < 256; return ( {view === "workers" ? ( ) : view === "queue" ? ( ) : ( )} { const Icon = viewIcons[value]; return { label: (
{!isTiny && ( {t(`tab.${value}`)} )}
), value, }; })} value={view} onChange={(value) => { const nextView = viewBySegmentValue[value]; if (nextView) { setView(nextView); } }} size="xs" /> {view === "queue" && ( <> {!isTiny && } {!isTiny && } {t("currentIndex", { start: String(transcodingData.data.queue.startIndex + 1), end: String(transcodingData.data.queue.endIndex + 1), total: String(transcodingData.data.queue.totalCount), })} )}
); }