import { Button as e } from "../../../components/ui/button.js";
import { Input as t } from "../../../components/ui/input.js";
import { Label as n } from "../../../components/ui/label.js";
import r from "../../../components/messages/CompletionMessagePaper.js";
import { useRunWorkflow as i } from "../../../hooks/useProcessor.js";
import { useUpsertSecret as a } from "../../../hooks/useSecrets.js";
import { useWorkbenchLayout as o } from "../../workbench/providers/WorkbenchLayoutProvider.js";
import "../../workbench/index.js";
import { useState as s } from "react";
import { jsx as c, jsxs as l } from "react/jsx-runtime";
import { Info as u, KeyRound as d, Loader2 as f } from "lucide-react";
//#region src/features/documents/renderers/SecretInputRenderer.tsx
var p = ({ parentWorkflow: p, workflow: m, document: h, isActive: g }) => {
	let _ = h.content.variables ?? [], v = (h.ui?.widgets)?.[0]?.options, y = v?.transition, b = v?.label ?? "Save & Continue", { workflow: x } = o(), S = x?.workspaceId, C = i(), w = a(), T = m.availableTransitions?.map((e) => e.id) ?? [], [E, D] = s(() => {
		let e = {};
		for (let t of _) e[t.key] = t.value ?? "";
		return e;
	}), [O, k] = s(!1), A = !!y && T.includes(y), j = !g || !A, M = async () => {
		if (!(!S || !y)) {
			k(!0);
			try {
				let e = [];
				for (let t of _) {
					let n = E[t.key]?.trim();
					!t.key.trim() || !n || (await w.mutateAsync({
						workspaceId: S,
						key: t.key,
						value: n
					}), e.push(t.key));
				}
				C.mutate({
					workflowId: p.id,
					runWorkflowPayloadDto: { transition: {
						id: y,
						workflowId: m.id,
						payload: { keys: e }
					} }
				});
			} finally {
				k(!1);
			}
		}
	};
	return /* @__PURE__ */ c(r, {
		role: "document",
		fullWidth: !0,
		timestamp: new Date(h.createdAt),
		children: /* @__PURE__ */ l("div", {
			className: "flex flex-col gap-4 p-1",
			children: [
				/* @__PURE__ */ c("div", {
					className: "text-sm font-medium",
					children: "Secrets"
				}),
				_.map((e) => /* @__PURE__ */ l("div", {
					className: "flex flex-col gap-1.5",
					children: [/* @__PURE__ */ c(n, {
						className: "text-muted-foreground text-xs",
						children: e.key
					}), /* @__PURE__ */ c(t, {
						type: "password",
						placeholder: "Enter value...",
						value: E[e.key] ?? "",
						onChange: (t) => D((n) => ({
							...n,
							[e.key]: t.target.value
						})),
						disabled: j
					})]
				}, e.key)),
				/* @__PURE__ */ l("div", {
					className: "text-muted-foreground flex items-center gap-2 text-xs",
					children: [/* @__PURE__ */ c(u, { className: "h-3.5 w-3.5 shrink-0" }), /* @__PURE__ */ c("span", { children: "To add or remove other secrets, use the Secrets panel in the right sidebar." })]
				}),
				/* @__PURE__ */ c("div", {
					className: "flex justify-end",
					children: /* @__PURE__ */ l(e, {
						onClick: () => void M(),
						disabled: j || O,
						className: "w-48",
						children: [O ? /* @__PURE__ */ c(f, { className: "mr-2 h-4 w-4 animate-spin" }) : /* @__PURE__ */ c(d, { className: "mr-2 h-4 w-4" }), b]
					})
				})
			]
		})
	});
};
//#endregion
export { p as default };
