import { useTranslation } from "react-i18next";
import { Form } from "react-router";
import { FeatherCalendarPlus, FeatherPin, FeatherPlug, FeatherStickyNote, FeatherTrash2 } from "@subframe/core";
import type { AdminConnectorListVM, AdminConnectorRow, AdminTenantNoteListVM } from "@hivegrid/view-models";
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
import { BannerAlert } from "~/ui/components/BannerAlert";
import { Button } from "~/ui/components/Button";
import { Card } from "~/ui/components/Card";
import { Checkbox } from "~/ui/components/Checkbox";
import { EmptyState } from "~/ui/components/EmptyState";
import { NumberInput } from "~/ui/components/NumberInput";
import { Select } from "~/ui/components/Select";
import { Table } from "~/ui/components/Table";
import { TextArea } from "~/ui/components/TextArea";
import { TextInput } from "~/ui/components/TextInput";
import { useLocaleFormatters } from "~/locale/format";
import { subscriptionStatusLabelKey, translateOrHumanize } from "./adminEnumLabels";
export type AdminTenantTrialInfo = {
status: string | null;
trialEndsAtIso: string | null;
};
export type AdminTenantOperationsPanelProps = {
connectors: AdminConnectorListVM;
notes: AdminTenantNoteListVM;
trial: AdminTenantTrialInfo;
noteCategories: readonly string[];
csrf: string;
submitting: boolean;
feedback?: { success?: string; error?: string };
};
/**
* AK-P19 DoD #3 โ AD-28 interim panel on the admin tenant detail: trial
* extension, subscription feature connectors (Abo-Baukasten) and operator
* notes. VMs in, action forms out โ no data fetching in here.
*/
export function AdminTenantOperationsPanel({ connectors, notes, trial, noteCategories, csrf, submitting, feedback }: AdminTenantOperationsPanelProps): React.JSX.Element {
return (
{feedback?.success ? {feedback.success} : null}
{feedback?.error ? {feedback.error} : null}
);
}
function TrialCard({ trial, csrf, submitting }: { trial: AdminTenantTrialInfo; csrf: string; submitting: boolean }): React.JSX.Element {
const { t } = useTranslation();
const formatters = useLocaleFormatters();
return (
{t("admin.tenantOps.trial.title")}
{t("admin.tenantOps.trial.description")}
{/* Printed the raw `trial` next to a translated "Aktiv" (audit I18N-02). */}
{trial.status ? translateOrHumanize(t, subscriptionStatusLabelKey(trial.status), trial.status) : t("admin.tenantOps.trial.noSubscription")}
{trial.trialEndsAtIso
? t("admin.tenantOps.trial.endsAt", { date: formatters.dateTime(new Date(trial.trialEndsAtIso)) })
: t("admin.tenantOps.trial.noTrial")}
{/* NumberInput is a fixed 192px-wide component โ the column must match or the stepper gets overlapped. */}
);
}
function ConnectorsCard({ connectors, csrf, submitting }: { connectors: AdminConnectorListVM; csrf: string; submitting: boolean }): React.JSX.Element {
const { t } = useTranslation();
const ready = connectors.status === "ready" ? connectors.data : null;
return (
{t("admin.connectors.title")}
{t("admin.connectors.description")}
{ready ? (
{t("admin.connectors.enabledCount", { count: ready.enabledCount })}
{t("admin.connectors.overriddenCount", { count: ready.overriddenCount })}
) : null}
{connectors.status === "empty" || !ready ? (
) : (
{t("admin.connectors.columns.feature")}
{t("admin.connectors.columns.effective")}
{t("admin.connectors.columns.override")}
}
>
{ready.rows.map((row) => (
))}
)}
);
}
function ConnectorRow({ row, csrf, submitting }: { row: AdminConnectorRow; csrf: string; submitting: boolean }): React.JSX.Element {
const { t, i18n } = useTranslation();
const label = i18n.exists(row.labelKey) ? t(row.labelKey) : row.featureKey;
return (
{label}
{t(row.baseEnabled ? "admin.connectors.baseEnabled" : "admin.connectors.baseDisabled")}
{t(row.effectiveEnabled ? "admin.connectors.state.on" : "admin.connectors.state.off")}
{row.overridden ? {t("admin.connectors.state.overridden")} : null}
{row.toggleable ? (
) : (
{t("admin.connectors.notToggleable")}
)}
);
}
function NotesCard({ notes, noteCategories, csrf, submitting }: { notes: AdminTenantNoteListVM; noteCategories: readonly string[]; csrf: string; submitting: boolean }): React.JSX.Element {
const { t } = useTranslation();
const formatters = useLocaleFormatters();
const ready = notes.status === "ready" ? notes.data : null;
return (
{t("admin.tenantNotes.title")}
{t("admin.tenantNotes.description")}
{notes.status === "empty" || !ready ? (
) : (
{ready.rows.map((note) => (
{t(note.categoryLabelKey)}
{note.pinned ? {t("admin.tenantNotes.pinnedLabel")} : null}
{note.bodyMarkdown}
{note.authorLabel.startsWith("admin.") ? t(note.authorLabel) : note.authorLabel} ยท {formatters.dateTime(new Date(note.createdAtIso))}
))}
)}
);
}