"use client" import { useServerData } from "@/app/context/server-data-context" import { BackIcon } from "@/components/Icon" import ServerFlag from "@/components/ServerFlag" import { ServerDetailLoading } from "@/components/loading/ServerDetailLoading" import { Badge } from "@/components/ui/badge" import { Card, CardContent } from "@/components/ui/card" import { cn, formatBytes, formatNezhaInfo } from "@/lib/utils" import countries from "i18n-iso-countries" import enLocale from "i18n-iso-countries/langs/en.json" import { useTranslations } from "next-intl" import { notFound, useRouter } from "next/navigation" import { useEffect, useState } from "react" countries.registerLocale(enLocale) export default function ServerDetailClient({ server_id, }: { server_id: number }) { const t = useTranslations("ServerDetailClient") const router = useRouter() const [hasHistory, setHasHistory] = useState(false) useEffect(() => { window.scrollTo({ top: 0, left: 0, behavior: "instant" }) }, []) useEffect(() => { const previousPath = sessionStorage.getItem("fromMainPage") if (previousPath) { setHasHistory(true) } }, []) const linkClick = () => { if (hasHistory) { router.back() } else { router.push(`/`) } } const { data: serverList, error, isLoading } = useServerData() const serverData = serverList?.result?.find((item) => item.id === server_id) if (!serverData && !isLoading) { notFound() } if (error) { return ( <>

{error.message}

{t("detail_fetch_error_message")}

) } if (!serverData) return const { name, online, uptime, version, arch, mem_total, disk_total, country_code, platform, platform_version, cpu_info, gpu_info, load_1, load_5, load_15, net_out_transfer, net_in_transfer, last_active_time_string, } = formatNezhaInfo(serverData) return (
{name}

{t("status")}

{online ? t("Online") : t("Offline")}

{t("Uptime")}

{" "} {uptime / 86400 >= 1 ? (uptime / 86400).toFixed(0) + " " + t("Days") : (uptime / 3600).toFixed(0) + " " + t("Hours")}{" "}
{version && (

{t("Version")}

{version}
)} {arch && (

{t("Arch")}

{arch}
)}

{t("Mem")}

{formatBytes(mem_total)}

{t("Disk")}

{formatBytes(disk_total)}
{country_code && (

{t("Region")}

{countries.getName(country_code, "en")}
)}
{platform && (

{t("System")}

{" "} {platform} - {platform_version}{" "}
)} {cpu_info && cpu_info.length > 0 && (

{t("CPU")}

{cpu_info.join(", ")}
)} {gpu_info && gpu_info.length > 0 && (

{"GPU"}

{gpu_info.join(", ")}
)}

{t("Load")}

{load_1 || "0.00"} / {load_5 || "0.00"} / {load_15 || "0.00"}

{t("Upload")}

{net_out_transfer ? (
{formatBytes(net_out_transfer)}
) : (
Unknown
)}

{t("Download")}

{net_in_transfer ? (
{formatBytes(net_in_transfer)}
) : (
Unknown
)}

{t("LastActive")}

{last_active_time_string ? last_active_time_string : "N/A"}
) }