"use client";
"use client";
import { i as e, n as t, r as n, t as r } from "../../../accordion-D-o5VBR2.js";
import { cn as i } from "../../../lib/utils.js";
import { t as a } from "../../../dist-Ber_p4PA.js";
import { n as o, r as s, t as c } from "../../../collapsible-Dt__KKUJ.js";
import { CopyButton as l } from "../atoms/copy-button.js";
import { JsonHighlight as u } from "../atoms/json-highlight.js";
import * as d from "react";
import { Fragment as f, jsx as p, jsxs as m } from "react/jsx-runtime";
import { CheckCircle2 as h, ChevronRight as g, Code as _, Loader2 as v, Table as y, TriangleAlert as b, Wrench as x } from "lucide-react";
//#region lib/components/ui/molecules/tool-call-accordion.tsx
var S = a("font-mono text-xs transition-colors", {
	variants: { state: {
		calling: "text-muted-foreground hover:text-foreground",
		complete: "text-muted-foreground hover:text-foreground",
		error: "text-destructive hover:text-destructive/80"
	} },
	defaultVariants: { state: "calling" }
}), C = a("absolute -top-0.5 right-0 size-2 shrink-0 rounded-full ring-2 ring-background", {
	variants: { state: {
		calling: "animate-pulse bg-orange-400",
		complete: "bg-green-500",
		error: "bg-destructive"
	} },
	defaultVariants: { state: "calling" }
});
function w(e, t = 140) {
	return e.length > t ? `${e.slice(0, t).trimEnd()}...` : e;
}
function T(e) {
	if (typeof e == "string") try {
		return JSON.stringify(JSON.parse(e), null, 2);
	} catch {
		return e;
	}
	return JSON.stringify(e, null, 2) ?? "null";
}
function E(e) {
	if (typeof e == "string") {
		try {
			let t = JSON.parse(e);
			if (typeof t == "object" && t && !Array.isArray(t)) return t;
		} catch {
			return { value: e };
		}
		return { value: e };
	}
	return typeof e == "object" && e && !Array.isArray(e) ? e : { value: e };
}
function D(e) {
	if (typeof e == "string") return w(e.replace(/\s+/g, " "));
	if (typeof e == "number" || typeof e == "boolean" || e == null) return String(e);
	if (Array.isArray(e)) return `${e.length} item${e.length === 1 ? "" : "s"}`;
	if (typeof e == "object") {
		let t = Object.keys(e).length;
		return `${t} field${t === 1 ? "" : "s"}`;
	}
	return String(e);
}
function O(e) {
	return typeof e == "string" && e.length > 180 || Array.isArray(e) || typeof e == "object" && !!e;
}
function k({ activeView: e, panelView: t, children: n, lazy: r = !1 }) {
	let a = e === t, [o, s] = d.useState(a || !r);
	return d.useEffect(() => {
		a && s(!0);
	}, [a]), o ? /* @__PURE__ */ p("div", {
		className: i(!a && "hidden"),
		children: n
	}) : null;
}
function A({ label: e, value: t }) {
	let [, n] = d.useTransition(), [r, i] = d.useState(!1), a = O(t);
	return /* @__PURE__ */ m("div", {
		className: "grid gap-1 px-3 py-2.5 sm:grid-cols-[minmax(0,8rem)_minmax(0,1fr)] sm:gap-3",
		children: [/* @__PURE__ */ p("dt", {
			className: "font-medium text-[11px] text-muted-foreground uppercase tracking-[0.08em]",
			children: e
		}), /* @__PURE__ */ m("dd", {
			className: "min-w-0 space-y-2 text-foreground/90 text-xs",
			children: [
				/* @__PURE__ */ p("span", {
					className: "wrap-break-word block whitespace-pre-wrap",
					children: D(t)
				}),
				a && /* @__PURE__ */ p("button", {
					className: "inline-flex items-center rounded-md border border-border/60 px-2 py-1 font-medium text-[11px] text-muted-foreground transition-colors hover:bg-muted/40 hover:text-foreground dark:border-white/10",
					onClick: () => n(() => i((e) => !e)),
					type: "button",
					children: r ? "Show less" : "Show more"
				}),
				r && /* @__PURE__ */ p(u, {
					className: "rounded-lg border border-border/60 bg-background/80 dark:border-white/10",
					code: T(t)
				})
			]
		})]
	});
}
var j = d.memo(function({ value: e }) {
	return /* @__PURE__ */ p("div", {
		className: "overflow-hidden rounded-lg border border-border/60 bg-background/80 dark:border-white/10",
		children: /* @__PURE__ */ p("dl", {
			className: "divide-y divide-border/50 dark:divide-white/10",
			children: d.useMemo(() => Object.entries(E(e)), [e]).map(([e, t]) => /* @__PURE__ */ p(A, {
				label: e,
				value: t
			}, e))
		})
	});
}), M = d.memo(function({ label: e, value: t, view: n = "table", className: r, ...a }) {
	let o = d.useMemo(() => T(t), [t]);
	return /* @__PURE__ */ m("section", {
		className: i("space-y-2", r),
		...a,
		children: [
			/* @__PURE__ */ m("div", {
				className: "flex items-center justify-between gap-3",
				children: [/* @__PURE__ */ p("h4", {
					className: "font-medium text-foreground text-xs",
					children: e
				}), /* @__PURE__ */ p(l, {
					className: "size-7 shrink-0 text-muted-foreground hover:text-foreground",
					content: o,
					size: "icon",
					variant: "ghost"
				})]
			}),
			/* @__PURE__ */ p(k, {
				activeView: n,
				panelView: "table",
				children: /* @__PURE__ */ p(j, { value: t })
			}),
			/* @__PURE__ */ p(k, {
				activeView: n,
				lazy: !0,
				panelView: "code",
				children: /* @__PURE__ */ p(u, {
					className: "rounded-lg border border-border/60 bg-background/80 dark:border-white/10",
					code: o
				})
			})
		]
	});
});
function N({ title: e, description: t, details: n }) {
	return /* @__PURE__ */ m(c, {
		className: "rounded-lg border border-destructive/25 bg-destructive/[0.04] dark:border-destructive/20 dark:bg-destructive/[0.06]",
		"data-slot": "tool-call-error-notice",
		disabled: !n,
		children: [/* @__PURE__ */ m(s, {
			className: i("group flex w-full items-start gap-2.5 px-3 py-2.5 text-left", n && "cursor-pointer"),
			children: [
				/* @__PURE__ */ p(b, { className: "mt-0.5 size-3.5 shrink-0 text-destructive" }),
				/* @__PURE__ */ m("div", {
					className: "min-w-0 flex-1 space-y-0.5",
					children: [/* @__PURE__ */ p("p", {
						className: "font-medium text-foreground text-sm",
						children: e
					}), /* @__PURE__ */ p("p", {
						className: "text-muted-foreground text-xs",
						children: t
					})]
				}),
				n && /* @__PURE__ */ m(f, { children: [/* @__PURE__ */ m("span", {
					className: "mt-0.5 inline-flex shrink-0 items-center gap-1 text-[11px] text-muted-foreground group-data-[state=open]:hidden",
					children: ["Details", /* @__PURE__ */ p(g, { className: "size-3" })]
				}), /* @__PURE__ */ m("span", {
					className: "mt-0.5 hidden shrink-0 items-center gap-1 text-[11px] text-muted-foreground group-data-[state=open]:inline-flex",
					children: ["Hide", /* @__PURE__ */ p(g, { className: "size-3 rotate-90" })]
				})] })
			]
		}), n && /* @__PURE__ */ p(o, { children: /* @__PURE__ */ m("div", {
			className: "relative rounded-b-lg border-border/50 border-t bg-card px-3 py-2.5 dark:border-white/10",
			children: [/* @__PURE__ */ p(l, {
				className: "absolute top-2 right-2 size-6 text-muted-foreground/60 hover:text-muted-foreground",
				content: n,
				size: "icon",
				variant: "ghost"
			}), /* @__PURE__ */ p("pre", {
				className: "wrap-break-word overflow-auto whitespace-pre-wrap pr-8 font-mono text-[11px] text-muted-foreground leading-relaxed",
				children: n
			})]
		}) })]
	});
}
function P({ className: e, ...t }) {
	return /* @__PURE__ */ p(r, {
		className: i("w-full", e),
		"data-slot": "tool-call-accordion",
		...t
	});
}
function F({ className: e, ...t }) {
	return /* @__PURE__ */ p(n, {
		className: i("w-full overflow-hidden rounded-xl border border-border/50 bg-card/75 shadow-sm last:border-b dark:border-white/10 dark:shadow-black/20", e),
		"data-slot": "tool-call-accordion-item",
		...t
	});
}
function I({ className: t, state: n, toolName: r, icon: a, showStateIndicator: o = !0, ...s }) {
	let c = n ?? "calling", l = a ?? /* @__PURE__ */ p(x, { className: "size-3.5 text-muted-foreground" }), u = {
		calling: /* @__PURE__ */ p(v, { className: "size-3 shrink-0 animate-spin text-orange-500" }),
		complete: /* @__PURE__ */ p(h, { className: "size-3 shrink-0 text-green-500" }),
		error: /* @__PURE__ */ p(b, { className: "size-3 shrink-0 text-destructive" })
	}, d = {
		calling: "Running",
		complete: "Completed",
		error: "Failed"
	};
	return /* @__PURE__ */ m(e, {
		className: i("items-center gap-3 px-3 py-3 hover:bg-muted/15 hover:no-underline [&>svg]:translate-y-0 [&>svg]:self-center", S({ state: c }), t),
		"data-slot": "tool-call-accordion-trigger",
		...s,
		children: [
			/* @__PURE__ */ m("div", {
				className: "relative shrink-0",
				children: [/* @__PURE__ */ p("div", {
					className: "flex size-8 items-center justify-center rounded-full bg-muted/45 ring-1 ring-border/50",
					children: l
				}), o && /* @__PURE__ */ p("span", {
					"aria-hidden": "true",
					className: C({ state: c })
				})]
			}),
			/* @__PURE__ */ p("div", {
				className: "min-w-0 flex-1 text-left",
				children: /* @__PURE__ */ p("span", {
					className: "block truncate text-foreground text-xs",
					children: r
				})
			}),
			/* @__PURE__ */ m("span", {
				className: i("inline-flex shrink-0 items-center gap-1.5 self-center text-[11px] text-muted-foreground leading-none", c === "error" && "text-destructive"),
				children: [u[c], d[c]]
			})
		]
	});
}
function L({ className: e, children: n, view: r, onViewChange: a, showViewToggle: o = !0, args: s, result: c, errorNotice: l, ...u }) {
	let [f, h] = d.useState("table"), [, g] = d.useTransition(), v = r ?? f, b = (e) => {
		a?.(e), r === void 0 && g(() => h(e));
	};
	return /* @__PURE__ */ p(t, {
		className: "w-full border-border/50 border-t bg-muted/10 dark:border-white/10",
		"data-slot": "tool-call-accordion-content",
		...u,
		children: /* @__PURE__ */ m("div", {
			className: i("space-y-3 overflow-auto px-3 py-3", e),
			children: [o && /* @__PURE__ */ m("div", {
				className: "flex items-center justify-between gap-3",
				children: [/* @__PURE__ */ p("p", {
					className: "truncate text-[11px] text-muted-foreground",
					children: "Inspect payload and response"
				}), /* @__PURE__ */ m("div", {
					className: "inline-flex shrink-0 items-center gap-0.5 rounded-lg border border-border/60 bg-background/70 p-0.5 shadow-sm dark:border-white/10",
					children: [/* @__PURE__ */ m("button", {
						className: i("inline-flex h-6.5 items-center justify-center gap-1.5 rounded-md px-2.5 text-[11px] transition-colors", v === "table" ? "bg-background text-foreground shadow-sm ring-1 ring-border/60" : "text-muted-foreground hover:bg-background/60 hover:text-foreground"),
						onClick: () => b("table"),
						type: "button",
						children: [/* @__PURE__ */ p(y, { className: "size-3.5" }), "Table"]
					}), /* @__PURE__ */ m("button", {
						className: i("inline-flex h-6.5 items-center justify-center gap-1.5 rounded-md px-2.5 text-[11px] transition-colors", v === "code" ? "bg-background text-foreground shadow-sm ring-1 ring-border/60" : "text-muted-foreground hover:bg-background/60 hover:text-foreground"),
						onClick: () => b("code"),
						type: "button",
						children: [/* @__PURE__ */ p(_, { className: "size-3.5" }), "JSON"]
					})]
				})]
			}), /* @__PURE__ */ m("div", {
				className: "space-y-3",
				children: [
					n,
					l && /* @__PURE__ */ p(N, { ...l }),
					s !== void 0 && /* @__PURE__ */ p(M, {
						label: "Parameters",
						value: s,
						view: v
					}),
					c !== void 0 && /* @__PURE__ */ p(M, {
						label: "Response",
						value: c,
						view: v
					})
				]
			})]
		})
	});
}
//#endregion
export { P as ToolCallAccordion, L as ToolCallAccordionContent, F as ToolCallAccordionItem, I as ToolCallAccordionTrigger };
