"use client"; import Link from "next/link"; import clsx from "clsx"; import { useMutation, useQueryClient } from "@tanstack/react-query"; import { api, type Instance, type License } from "@/lib/api"; import { daysRemaining, formatDate, licenceState } from "@/lib/format"; import { StatePill } from "./StatePill"; const STRIPE = { valid: "before:bg-valid", warn: "before:bg-warn", expired: "before:bg-expired", none: "before:bg-accent", } as const; export function InstanceCard({ instance, license, reapAfterDays, }: { instance: Instance; license?: License; reapAfterDays?: number; }) { const state = licenceState(license?.expires_at, Boolean(license)); const days = license ? daysRemaining(license.expires_at) : 0; const cloud = instance.deployment === "cloud"; const termDays = instance.tier === "free" ? 30 : 365; const deleteInDays = license && reapAfterDays ? daysRemaining(license.expires_at) + reapAfterDays : null; const qc = useQueryClient(); const renew = useMutation({ mutationFn: () => api.renewInstance(instance.instance_id), onSuccess: () => qc.invalidateQueries({ queryKey: ["account"] }), }); const canRenew = instance.tier === "free" && license !== undefined && days <= 7; return (

{instance.name || "Unnamed instance"}

{cloud ? "Cloud" : "Self-hosted"} {instance.tier ? ` · ${instance.tier.replace("_", " ")}` : ""}

{state === "expired" && (

Servers and monitors are still running, and your agents keep their keys. Changes are disabled until you renew.

)} {state === "expired" && deleteInDays !== null && (

{deleteInDays <= 0 ? "Scheduled for deletion." : `Deleted in ${deleteInDays} ${deleteInDays === 1 ? "day" : "days"} unless renewed.`}

)} {state === "none" && (

You have paid for this but it is not attached to an install yet, so no licence has been issued. Linking takes a minute.

)} {license && state !== "expired" && (
{days} days remaining
Renews {formatDate(license.expires_at)}
)}
{state === "none" ? ( Link an install ) : cloud && instance.slug ? ( Open {instance.slug}.vantage.hostxtra.co.uk ) : ( {state === "expired" ? "Renew and download" : "Licence and download"} )} {canRenew && ( )}
); }