import Link from "next/link";
import { getTranslations } from "next-intl/server";
import { Network, Pencil, Plus, Trash2 } from "lucide-react";
import type { Prisma } from "@prisma/client";
import {
addRaci,
createService,
cycleRaci,
deleteRaci,
deleteService,
updateService,
} from "@/server/actions/services";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Textarea } from "@/components/ui/textarea";
import { Modal } from "@/components/modal";
import { SegmentedRating } from "@/components/segmented-rating";
import { CiaBadge, CiaLegend, CriticalityPill, Pill, Tag } from "@/components/mockup-ui";
import { serviceRef, withQuery } from "@/lib/supplier";
import { riskLevel, riskRef, RISK_PILL_TONE } from "@/lib/risk";
import { ISA_CONTROLS } from "@/lib/isa-controls";
export type ServiceAssetDetail = Prisma.AssetGetPayload<{
include: {
serviceProfile: { include: { provider: { select: { id: true; name: true } } } };
raci: true;
riskAssets: { include: { risk: { select: { id: true; refNo: true; title: true; score: true } } } };
relationsFrom: { include: { relatedAsset: { select: { id: true; name: true; type: true; confidentiality: true; integrity: true; availability: true } } } };
relationsTo: { include: { asset: { select: { id: true; name: true } } } };
processAssets: { include: { process: { select: { id: true; name: true } } } };
};
}>;
const inputCls = "h-9 w-full rounded-md border border-input bg-transparent px-3 text-sm";
const RACI_TONE = { PROVIDER: "info", US: "violet", SHARED: "warn" } as const;
/* ─────────────────────── Detail-Cockpit ─────────────────────── */
export async function ServiceDetailModal({ service, canWrite, backHref = "/suppliers?tab=services" }: { service: ServiceAssetDetail; canWrite: boolean; backHref?: string }) {
const t = await getTranslations("services");
const ta = await getTranslations("assets");
const tParty = await getTranslations("raciParty");
const tCrit = await getTranslations("criticality");
const tType = await getTranslations("assetType");
const tLevel = await getTranslations("riskLevel");
const tRisks = await getTranslations("risks");
const tDep = await getTranslations("dependencies");
const tc = await getTranslations("common");
const tp = await getTranslations("processes");
const p = service.serviceProfile!;
return (
{p.notes} {ta("processes")} {tc("none")} {tc("none")} {ta("relationReverseHint")} {tc("none")} {t("raci")} {t("raciNote")} {t("raciEmpty")}
{service.processAssets.map((pa) => (
)}
{service.relationsTo.length > 0 && (
<>
{service.relationsFrom.map((rel) => (
))}
{rel.relatedAsset.name}
{service.relationsTo.map((rel) => (
>
)}
{service.riskAssets.map((ra) => (