import { cn } from "./index3.js";
import { useControllableState } from "./index11.js";
import { AnimatePresence } from "./index308.js";
import { motion } from "./index359.js";
import { AICodeBlock } from "./index414.js";
import { cva } from "class-variance-authority";
import { AlertCircle, Check, ChevronDown, ChevronRight, Clock, Code, Wrench } from "lucide-react";
import { jsx, jsxs } from "react/jsx-runtime";
//#region src/components/organisms/ai/AIToolCall/AIToolCall.tsx
var toolCallVariants = cva("overflow-hidden rounded-xl border transition-colors", {
	variants: { status: {
		pending: "border-border bg-muted",
		running: "border-primary bg-primary/10",
		success: "border-success/50 bg-success/10",
		error: "border-destructive/50 bg-destructive/10"
	} },
	defaultVariants: { status: "pending" }
});
var statusIconVariants = cva("size-4", {
	variants: { status: {
		pending: "text-muted-foreground",
		running: "text-primary animate-spin motion-reduce:animate-none",
		success: "text-success",
		error: "text-destructive"
	} },
	defaultVariants: { status: "pending" }
});
function StatusIcon({ status, className }) {
	const iconClass = cn(statusIconVariants({ status }), className);
	switch (status) {
		case "running": return /* @__PURE__ */ jsx(Clock, { className: iconClass });
		case "success": return /* @__PURE__ */ jsx(Check, { className: cn(iconClass, "delight-check-bounce motion-reduce:!animate-none") });
		case "error": return /* @__PURE__ */ jsx(AlertCircle, { className: cn(iconClass, "delight-shake motion-reduce:!animate-none") });
		default: return /* @__PURE__ */ jsx(Wrench, { className: iconClass });
	}
}
StatusIcon.displayName = "StatusIcon";
function AIToolCallHeader({ toolName, status, isOpen, onToggle, className }) {
	return /* @__PURE__ */ jsxs("button", {
		type: "button",
		onClick: onToggle,
		"aria-expanded": isOpen,
		className: cn("flex items-center justify-between w-full px-4 py-3 transition-colors hover:bg-foreground/5 focus-visible:outline-2 focus-visible:outline-offset-[-2px] focus-visible:outline-ring", className),
		children: [/* @__PURE__ */ jsxs("div", {
			className: "flex items-center gap-3",
			children: [/* @__PURE__ */ jsx(StatusIcon, {
				status,
				"aria-hidden": "true"
			}), /* @__PURE__ */ jsxs("div", {
				className: "flex flex-col items-start",
				children: [/* @__PURE__ */ jsx("span", {
					className: "text-sm font-medium text-foreground",
					children: toolName
				}), /* @__PURE__ */ jsx("span", {
					className: "text-xs text-quaternary-foreground",
					children: {
						pending: "Pending",
						running: "Running...",
						success: "Completed",
						error: "Failed"
					}[status]
				})]
			})]
		}), isOpen ? /* @__PURE__ */ jsx(ChevronDown, {
			className: "size-4 text-muted-foreground",
			"aria-hidden": "true"
		}) : /* @__PURE__ */ jsx(ChevronRight, {
			className: "size-4 text-muted-foreground rtl:rotate-180",
			"aria-hidden": "true"
		})]
	});
}
AIToolCallHeader.displayName = "AIToolCallHeader";
function ToolCallSection({ title, icon, children, className }) {
	return /* @__PURE__ */ jsxs("div", {
		className: cn("space-y-2", className),
		children: [/* @__PURE__ */ jsxs("div", {
			className: "flex items-center gap-2 text-xs font-medium text-quaternary-foreground uppercase tracking-wide",
			children: [icon, title]
		}), children]
	});
}
ToolCallSection.displayName = "ToolCallSection";
function AIToolCall({ toolPart, defaultOpen = false, open: controlledOpen, onOpenChange, className }) {
	const [isOpen, setIsOpen] = useControllableState({
		value: controlledOpen,
		defaultValue: defaultOpen,
		onChange: onOpenChange
	});
	const status = toolPart.status || "pending";
	const handleToggle = () => {
		setIsOpen(!isOpen);
	};
	const formatValue = (value) => {
		if (typeof value === "string") return value;
		return JSON.stringify(value, null, 2);
	};
	return /* @__PURE__ */ jsxs("div", {
		"data-slot": "ai-tool-call",
		className: cn(toolCallVariants({ status }), className),
		children: [/* @__PURE__ */ jsx(AIToolCallHeader, {
			toolName: toolPart.toolName,
			status,
			isOpen,
			onToggle: handleToggle
		}), /* @__PURE__ */ jsx(AnimatePresence, { children: isOpen && /* @__PURE__ */ jsx(motion.div, {
			initial: {
				height: 0,
				opacity: 0
			},
			animate: {
				height: "auto",
				opacity: 1
			},
			exit: {
				height: 0,
				opacity: 0
			},
			transition: { duration: .2 },
			className: "overflow-hidden",
			children: /* @__PURE__ */ jsxs("div", {
				className: "px-4 pb-4 space-y-4",
				children: [
					/* @__PURE__ */ jsxs("div", {
						className: "text-xs text-muted-foreground font-mono",
						children: ["ID: ", toolPart.toolCallId]
					}),
					toolPart.args && Object.keys(toolPart.args).length > 0 && /* @__PURE__ */ jsx(ToolCallSection, {
						title: "Input",
						icon: /* @__PURE__ */ jsx(Code, { className: "size-3" }),
						children: /* @__PURE__ */ jsx(AICodeBlock, {
							code: formatValue(toolPart.args),
							language: "json",
							showHeader: false,
							showCopyButton: true,
							size: "sm"
						})
					}),
					toolPart.result !== void 0 && /* @__PURE__ */ jsx(ToolCallSection, {
						title: "Output",
						icon: /* @__PURE__ */ jsx(Code, { className: "size-3" }),
						children: /* @__PURE__ */ jsx(AICodeBlock, {
							code: formatValue(toolPart.result),
							language: "json",
							showHeader: false,
							showCopyButton: true,
							size: "sm"
						})
					}),
					toolPart.error && /* @__PURE__ */ jsx("div", {
						className: "p-3 rounded-lg bg-destructive/20 border border-destructive/50",
						children: /* @__PURE__ */ jsxs("div", {
							className: "flex items-start gap-2",
							children: [/* @__PURE__ */ jsx(AlertCircle, { className: "size-4 text-destructive mt-0.5 shrink-0" }), /* @__PURE__ */ jsx("p", {
								className: "text-sm text-destructive",
								children: toolPart.error
							})]
						})
					})
				]
			})
		}) })]
	});
}
AIToolCall.displayName = "AIToolCall";
function AIToolCallList({ toolCalls, defaultAllOpen = false, className }) {
	return /* @__PURE__ */ jsx("div", {
		"data-slot": "ai-tool-call-list",
		className: cn("space-y-2", className),
		children: toolCalls.map((toolCall) => /* @__PURE__ */ jsx(AIToolCall, {
			toolPart: toolCall,
			defaultOpen: defaultAllOpen
		}, toolCall.toolCallId))
	});
}
AIToolCallList.displayName = "AIToolCallList";
//#endregion
export { AIToolCall, AIToolCallHeader, AIToolCallList, StatusIcon, ToolCallSection, statusIconVariants, toolCallVariants };

//# sourceMappingURL=index446.js.map