"use client"; import { Badge, Box, Flex, Group, Progress, Stack, Text, Tooltip, VisuallyHidden } from "@mantine/core"; import { IconCube, IconUsersGroup } from "@tabler/icons-react"; import { clientApi } from "@homarr/api/client"; import { formatNumber } from "@homarr/common"; import { useI18n } from "@homarr/translation/client"; import { WidgetEmptyState } from "../../common/empty-state"; import type { WidgetComponentProps } from "../../definition"; export default function MinecraftServerStatusWidget({ options, width, height, }: WidgetComponentProps<"minecraftServerStatus">) { const { data: result, isPending, error } = clientApi.widget.minecraft.getServerStatus.useQuery(options); const t = useI18n(); if (isPending) { return ( {t("common.action.loading")} ); } if (error && !result) throw error; if (!result) return ; const { data } = result; const title = options.title.trim().length > 0 ? options.title : options.domain; const isDense = width < 220 || height < 120; const showServerIcon = !isDense && height >= 144; const showMetadata = width >= 260 && height >= 180; const showCapacity = width >= 180 && height >= 140; const iconSize = Math.max(40, Math.min(80, width * 0.45, height * 0.45)); const playerPercent = data.online && data.players.max > 0 ? (data.players.online / data.players.max) * 100 : 0; return ( {data.online ? t("widget.minecraftServerStatus.status.online") : t("widget.minecraftServerStatus.status.offline")} {title} {showMetadata && ( {options.domain} {options.isBedrockServer && ( {t("widget.minecraftServerStatus.option.isBedrockServer.label")} )} )} {data.online && ( <> {!options.isBedrockServer && showServerIcon && (data.icon ? ( {`minecraft ) : ( ))} {formatNumber(data.players.online, 1)} / {formatNumber(data.players.max, 1)} {showCapacity && = 90 ? "orange" : "teal"} />} )} {showMetadata && !data.online && ( {options.domain} )} ); }