import { Badge, ClipboardText, LayerDialog, Text } from "@cloudhal/ui";
import { FileText, HandPalm } from "@phosphor-icons/react";
import { type ReactNode, useRef } from "react";
import { useT } from "../i18n/index.tsx";
import type { SkillSummary } from "../lib/api.ts";
import { isAgentScope, orderSkillScopes, skillCallSnippet } from "../lib/skills.ts";
import { useToolLabel } from "./Audit.tsx";
import { CodeHighlighted } from "./CodeHighlighted.tsx";
import { ScopeBadge } from "./ScopeBadge.tsx";
function Row({ label, hint, children }: { label: string; hint?: string; children: ReactNode }) {
return (
{label}
{children}
{hint && (
{hint}
)}
);
}
/** A scope as the agent-keys page shows it; scopes Studio doesn't know stay raw. */
export function SkillScope({ scope }: { scope: string }) {
if (isAgentScope(scope)) return ;
return (
{scope}
);
}
/** Tool that waits for a person under this skill: localised label, raw MCP name in mono. */
export function ApprovalTool({ tool }: { tool: string }) {
const label = useToolLabel();
return (
}>
{label(tool) === tool ? {tool} : label(tool)}
);
}
/**
* Everything about one skill in a `LayerDialog` (bottom sheet on phones): scopes, approvals,
* requirements, reference files, the `skill://` resource and a ready `tools/call` with `_meta`.
*/
export function SkillDetailDialog({
skill: current,
onOpenChange,
}: {
/** `undefined` closes the dialog (it stays mounted to animate). */
skill: SkillSummary | undefined;
onOpenChange: (open: boolean) => void;
}) {
const t = useT();
const last = useRef(current);
if (current) last.current = current;
const skill = current ?? last.current;
return (
{skill?.name ?? ""}
{skill?.description ?? ""}
{skill && (
{orderSkillScopes(skill.scopes).map((s) => (
))}
0 ? t("skills.detail.approvalHint") : undefined}
>
{skill.approval.length > 0 ? (
{skill.approval.map((tool) => (
))}
) : (
{t("skills.detail.noApproval")}
)}
{skill.requiresCapabilities.length > 0 && (
{skill.requiresCapabilities.map((c) => (
{c}
))}
)}
{skill.references.length > 0 ? (
{skill.references.map((r) => (
{r}
))}
) : (
{t("skills.detail.noReferences")}
)}
{t("skills.detail.call")}
)}
);
}