"use client";
import React from "react";
import { Badge, Box, Card, Flex, Group, Text } from "@mantine/core";
import { IconArrowsExchange, 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",
}: {
vpn: VpnInfo;
integrationName?: string;
variant?: "single" | "list";
}) {
const board = useRequiredBoard();
const compact = variant === "list";
const content = vpn ? (
) : (
);
if (compact) {
return (
{content}
);
}
return {content};
}
function VpnUnavailableContent({ compact, integrationName }: { compact: 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,
}: {
vpnStatus: string;
dnsStatus: string;
compact: boolean;
}) {
// 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;
return (
);
}
function VpnInfoColumn({
integrationName,
publicIp,
city,
country,
provider,
protocol,
compact,
}: {
integrationName?: string;
publicIp: string;
city: string;
country: string;
provider: string;
protocol: string;
compact: boolean;
}) {
return (
{integrationName ? (
{integrationName}
) : null}
{publicIp}
{city}, {country}
);
}
function VpnProviderDetails({ provider, protocol }: { provider: string; protocol: string }) {
return (
{provider}
{protocol}
);
}
function StatusDot({ status, size = 10 }: { status: string; size?: number }) {
return ;
}
function DnsStatusBadge({ status }: { status: string }) {
return (
}
>
DNS
);
}