import { Button as e } from "../../../components/ui/button.js";
import { Label as t } from "../../../components/ui/label.js";
import { RadioGroup as n, RadioGroupItem as r } from "../../../components/ui/radio-group.js";
import { Textarea as i } from "../../../components/ui/textarea.js";
import a from "../../../components/messages/CompletionMessagePaper.js";
import o from "../../../components/dynamic-form/MarkdownContent.js";
import { useDocumentTransition as s } from "./useDocumentTransition.js";
import { useState as c } from "react";
import { Fragment as l, jsx as u, jsxs as d } from "react/jsx-runtime";
import { Loader2 as f } from "lucide-react";
//#region src/features/documents/renderers/ChoicesRenderer.tsx
var p = ({ parentWorkflow: p, workflow: m, document: h, isActive: g }) => {
	let _ = h.content, { submit: v, canSubmit: y, isLoading: b } = s(p, m, h.ui), [x, S] = c(_.answer ?? ""), [C, w] = c(""), T = x === "__custom__", E = !!_.answer, D = () => {
		let e = T ? C.trim() : x;
		e && v({ answer: e });
	}, O = !g || !y || E;
	return /* @__PURE__ */ u(a, {
		role: "document",
		fullWidth: !0,
		timestamp: new Date(h.createdAt),
		children: /* @__PURE__ */ d("div", {
			className: "flex flex-col gap-4 p-1",
			children: [/* @__PURE__ */ u(o, { content: _.question }), E ? /* @__PURE__ */ d("div", {
				className: "text-muted-foreground text-sm",
				children: ["Answered: ", /* @__PURE__ */ u("span", {
					className: "text-foreground font-medium",
					children: _.answer
				})]
			}) : /* @__PURE__ */ d(l, { children: [
				/* @__PURE__ */ d(n, {
					value: x,
					onValueChange: S,
					disabled: O,
					children: [_.options.map((e, n) => /* @__PURE__ */ d("div", {
						className: "flex items-center gap-3",
						children: [/* @__PURE__ */ u(r, {
							value: e,
							id: `option-${n}`
						}), /* @__PURE__ */ u(t, {
							htmlFor: `option-${n}`,
							className: "cursor-pointer text-sm font-normal",
							children: e
						})]
					}, n)), _.allowCustomAnswer && /* @__PURE__ */ d("div", {
						className: "flex items-center gap-3",
						children: [/* @__PURE__ */ u(r, {
							value: "__custom__",
							id: "option-custom"
						}), /* @__PURE__ */ u(t, {
							htmlFor: "option-custom",
							className: "cursor-pointer text-sm font-normal",
							children: "Other"
						})]
					})]
				}),
				T && /* @__PURE__ */ u(i, {
					placeholder: "Type your answer...",
					value: C,
					onChange: (e) => w(e.target.value),
					disabled: O,
					className: "min-h-10",
					rows: 2
				}),
				/* @__PURE__ */ u("div", {
					className: "flex justify-end",
					children: /* @__PURE__ */ d(e, {
						type: "button",
						variant: "default",
						disabled: O || b || !x || T && !C.trim(),
						onClick: D,
						className: "w-48",
						children: [b && /* @__PURE__ */ u(f, { className: "h-4 w-4 animate-spin" }), "Submit"]
					})
				})
			] })]
		})
	});
};
//#endregion
export { p as default };
