"use client";
import React from "react";
import { Badge, Box, Card, Flex, Group, Text, VisuallyHidden } from "@mantine/core";
import {
IconArrowsExchange,
IconCircleCheckFilled,
IconCircleXFilled,
IconMapPin,
IconShieldCheck,
IconShieldX,
} from "@tabler/icons-react";
import type { RouterOutputs } from "@homarr/api";
import { useRequiredBoard } from "@homarr/boards/context";
import { useScopedI18n } from "@homarr/translation/client";
import { getStatusColor, RUNNING_STATUS } from "./helpers";
export type VpnInfo = RouterOutputs["widget"]["vpn"]["getSummaries"][number]["summary"];
export function VpnIntegrationCard({
vpn,
integrationName,
variant = "single",
dense = false,
}: {
vpn: VpnInfo;
integrationName?: string;
variant?: "single" | "list";
dense?: boolean;
}) {
const board = useRequiredBoard();
const compact = variant === "list";
const content = vpn ? (
) : (
);
if (compact) {
return (
{content}
);
}
return {content};
}
function VpnUnavailableContent({
compact,
dense,
integrationName,
}: {
compact: boolean;
dense: boolean;
integrationName?: string;
}) {
const t = useScopedI18n("widget.vpn");
return (
{/* Empty statuses render the shield and DNS badge in red (see getStatusColor). */}
{integrationName ? (
{integrationName}
) : null}
{t("serviceUnavailable")}
);
}
function VpnStatusColumn({
vpnStatus,
dnsStatus,
compact,
dense,
}: {
vpnStatus: string;
dnsStatus: string;
compact: boolean;
dense: boolean;
}) {
const t = useScopedI18n("widget.vpn");
// Connected shows a shield with a check; anything else (stopped or unavailable) shows a shield with a cross.
const ShieldIcon = vpnStatus === RUNNING_STATUS ? IconShieldCheck : IconShieldX;
const statusLabel = t(
vpnStatus === RUNNING_STATUS ? "status.running" : vpnStatus ? "status.notRunning" : "status.unavailable",
);
return (
);
}
function VpnInfoColumn({
integrationName,
publicIp,
city,
country,
provider,
protocol,
compact,
dense,
}: {
integrationName?: string;
publicIp: string;
city: string;
country: string;
provider: string;
protocol: string;
compact: boolean;
dense: boolean;
}) {
return (
{integrationName ? (
{integrationName}
) : null}
{publicIp || "—"}
{!dense && (city || country) && (
{[city, country].filter(Boolean).join(", ")}
)}
{!dense && (provider || protocol) && }
);
}
function VpnProviderDetails({ provider, protocol }: { provider: string; protocol: string }) {
return (
{provider}
{protocol}
);
}
function DnsStatusBadge({ status }: { status: string }) {
const t = useScopedI18n("widget.vpn");
const StatusIcon = status === RUNNING_STATUS ? IconCircleCheckFilled : IconCircleXFilled;
const statusLabel = t(
status === RUNNING_STATUS ? "status.running" : status ? "status.notRunning" : "status.unavailable",
);
return (
}
>
DNS
{statusLabel}
);
}