"use client"; import { Button } from "@app/components/ui/button"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@app/components/ui/dropdown-menu"; import { cn } from "@app/lib/cn"; import { ChevronDown } from "lucide-react"; import { useTranslations } from "next-intl"; import Link from "next/link"; export type ResourceSiteRow = { siteId: number; siteName: string; siteNiceId: string; online: boolean; }; type AggregateSitesStatus = "allOnline" | "partial" | "allOffline"; function aggregateSitesStatus( resourceSites: ResourceSiteRow[] ): AggregateSitesStatus { if (resourceSites.length === 0) { return "allOffline"; } const onlineCount = resourceSites.filter((rs) => rs.online).length; if (onlineCount === resourceSites.length) return "allOnline"; if (onlineCount > 0) return "partial"; return "allOffline"; } function aggregateStatusDotClass(status: AggregateSitesStatus): string { switch (status) { case "allOnline": return "bg-green-500"; case "partial": return "bg-yellow-500"; case "allOffline": default: return "bg-neutral-500"; } } export function ResourceSitesStatusCell({ orgId, resourceSites }: { orgId: string; resourceSites: ResourceSiteRow[]; }) { const t = useTranslations(); if (resourceSites.length === 0) { return -; } const aggregate = aggregateSitesStatus(resourceSites); const countLabel = t("multiSitesSelectorSitesCount", { count: resourceSites.length }); return ( {resourceSites.map((site) => { const isOnline = site.online; return (
{site.siteName}
{isOnline ? t("online") : t("offline")} ); })} ); }