import type { ReactNode } from "react"; import Link from "next/link"; import type { PoolOverview, PoolSubscriptionState } from "@peppa/core"; import { intlLocale, type Locale } from "@peppa/shared/i18n"; import { Badge } from "@/components/ui/badge"; import { getT } from "@/lib/i18n"; const hhmm = (d: Date, locale: Locale) => d.toLocaleTimeString(intlLocale(locale), { hour: "2-digit", minute: "2-digit", timeZone: process.env.PEPPA_TZ || undefined }); const KIND: Record = { claude: "Claude", codex: "ChatGPT", opencode: "OpenCode" }; function tone(s: PoolSubscriptionState): "ok" | "warn" | "danger" | "muted" | "primary" { if (s.status === "auth_error") return "danger"; if (s.status === "pending") return "muted"; if (s.limitedUntil) return "warn"; return s.activeSessions ? "primary" : "ok"; } /** * PEP-107/170: the subscriptions of a set as people see them — one status per row (at work, * free, limit until, sign-in error) and «следующая» on the one agents move to when theirs runs * out; `action` adds buttons per row. */ export async function PoolSubscriptions({ o, action }: { o: PoolOverview; action?: (s: PoolSubscriptionState) => ReactNode }) { const t = await getT(); if (!o.subscriptions.length) return

{t("Подписок пока нет.")}

; return ( ); } /** One line under the list: what happens when the subscription at work runs out. */ export async function PoolSummary({ o }: { o: PoolOverview }) { const t = await getT(); const resets = o.subscriptions.map((s) => s.limitedUntil).filter((d): d is Date => !!d).sort((a, b) => a.getTime() - b.getTime())[0]; let text: string; if (!o.subscriptions.length) text = t("Добавьте подписку — без неё агенты не запустятся."); else if (o.usableCount === 0) text = resets ? t("Все подписки кончились — агенты продолжат в {time}, когда сбросится лимит.", { time: hhmm(resets, t.locale) }) : t("Рабочих подписок нет — агенты стоят."); else if (o.usableCount === 1) text = t("Запасной подписки нет: когда эта кончится, агенты подождут сброса лимита. Добавьте ещё одну."); else text = t("Кончится одна — агенты перейдут на следующую."); return

{text}

; } /** PEP-170: the latest switches — who moved, from which subscription to which, when. */ export async function PoolSwitches({ o }: { o: PoolOverview }) { const t = await getT(); if (!o.switches.length) return null; return (
{t("Переключения")} {o.switches.map((x, i) => ( {x.at.toLocaleString(intlLocale(t.locale), { day: "numeric", month: "short", hour: "2-digit", minute: "2-digit", timeZone: process.env.PEPPA_TZ || undefined })} {" · "} {x.taskKey ? {x.taskKey} : t("агент №{id}", { id: x.sessionId ?? "?" })} {": "} {x.fromName} → {x.toName} {" "} ({x.reason === "threshold" ? t("почти кончилась") : t("кончилась")}) ))}
); }