import { useQuery } from "@tanstack/react-query"; import { CalendarDays, DollarSign } from "lucide-react"; import { useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import { type Domain, getDomains } from "@/api/domain"; import { cn } from "@/lib/utils"; import RemainPercentBar from "./RemainPercentBar"; const DomainNoteTags = ({ notes }: { notes?: string }) => { if (!notes) { return null; } const colors = [ "bg-blue-500 text-white", "bg-green-500 text-white", "bg-purple-500 text-white", "bg-red-500 text-white", "bg-gray-600 text-white", ]; const tags = notes .split(";") .map((tag) => tag.trim()) .filter((tag) => tag); return (
{tags.map((tag, index) => ( {tag} ))}
); }; const DomainCardInline = ({ domain }: { domain: Domain }) => { const { t } = useTranslation(); const expiresIn = domain.expires_in_days; const billingData = domain.BillingData || {}; const customBackgroundImage = (window as any).CustomBackgroundImage !== "" ? (window as any).CustomBackgroundImage : undefined; let statusColorClass = "bg-green-500"; if (expiresIn !== undefined && expiresIn <= 10) statusColorClass = "bg-red-500"; else if (expiresIn !== undefined && expiresIn <= 30) statusColorClass = "bg-yellow-500"; return (

{domain.Domain}

{billingData.registrar || "N/A"}
{t("domain.expiryPrefix")}:{" "} {billingData.endDate ? new Date(billingData.endDate).toLocaleDateString() : "N/A"}
{billingData.renewalPrice || "N/A"}
{expiresIn !== undefined ? `${expiresIn} ${t("domain.days")}` : "N/A"}
); }; const DomainCard = ({ domain }: { domain: Domain }) => { const { t } = useTranslation(); const expiresIn = domain.expires_in_days; const billingData = domain.BillingData || {}; const customBackgroundImage = (window as any).CustomBackgroundImage !== "" ? (window as any).CustomBackgroundImage : undefined; return (

{domain.Domain}

{billingData.registrar || t("domain.unknownRegistrar")}
{billingData.endDate ? new Date(billingData.endDate).toLocaleDateString() : "N/A"}
{billingData.renewalPrice || "N/A"}
{expiresIn !== undefined ? `${expiresIn}${t("domain.days")}` : "N/A"}
); }; export const DomainStatus = () => { const { data: domains, isLoading, error, } = useQuery({ queryKey: ["domains"], queryFn: getDomains, refetchInterval: 60 * 60 * 1000, }); const [inline, setInline] = useState("0"); useEffect(() => { const checkInlineSettings = () => { const isMobile = window.innerWidth < 768; if (!isMobile) { const inlineState = localStorage.getItem("inline"); if ((window as any).ForceCardInline) setInline("1"); else if (inlineState !== null) setInline(inlineState); } }; checkInlineSettings(); const handleStorageChange = () => checkInlineSettings(); window.addEventListener("storage", handleStorageChange); const handleViewChange = () => { const inlineState = localStorage.getItem("inline"); setInline(inlineState ?? "0"); }; window.addEventListener("nezha-view-change", handleViewChange); return () => { window.removeEventListener("storage", handleStorageChange); window.removeEventListener("nezha-view-change", handleViewChange); }; }, []); const filteredDomains = domains?.filter( (d) => d.Status === "verified" || d.Status === "expired", ); if (error || isLoading || !filteredDomains || filteredDomains.length === 0) { return null; } if (inline === "1") { return (
{filteredDomains.map((domain) => ( ))}
); } return (
{filteredDomains.map((domain) => ( ))}
); };