"use client";
import { cn } from "../../lib/utils.js";
import { Badge } from "../ui/badge.js";
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "../ui/collapsible.js";
import { CodeBlock } from "./code-block.js";
import { c } from "react/compiler-runtime";
import { isValidElement } from "react";
import { jsx, jsxs } from "react/jsx-runtime";
import { CheckCircleIcon, ChevronDownIcon, CircleIcon, ClockIcon, WrenchIcon, XCircleIcon } from "lucide-react";
const Tool = (r) => {
	let a = c(8), o, s;
	a[0] === r ? (o = a[1], s = a[2]) : ({className: o, ...s} = r, a[0] = r, a[1] = o, a[2] = s);
	let l;
	a[3] === o ? l = a[4] : (l = cn("not-prose mb-4 w-full rounded-md border", o), a[3] = o, a[4] = l);
	let u;
	return a[5] !== s || a[6] !== l ? (u = /* @__PURE__ */ jsx(Collapsible, {
		className: l,
		...s
	}), a[5] = s, a[6] = l, a[7] = u) : u = a[7], u;
};
var getStatusBadge = (e) => {
	let i = {
		"input-streaming": "Pending",
		"input-available": "Running",
		"approval-requested": "Awaiting Approval",
		"approval-responded": "Responded",
		"output-available": "Completed",
		"output-error": "Error",
		"output-denied": "Denied"
	};
	return /* @__PURE__ */ jsxs(Badge, {
		className: "gap-1.5 rounded-full text-xs",
		variant: "secondary",
		children: [{
			"input-streaming": /* @__PURE__ */ jsx(CircleIcon, { className: "size-4" }),
			"input-available": /* @__PURE__ */ jsx(ClockIcon, { className: "size-4 animate-pulse" }),
			"approval-requested": /* @__PURE__ */ jsx(ClockIcon, { className: "size-4 text-yellow-600" }),
			"approval-responded": /* @__PURE__ */ jsx(CheckCircleIcon, { className: "size-4 text-blue-600" }),
			"output-available": /* @__PURE__ */ jsx(CheckCircleIcon, { className: "size-4 text-green-600" }),
			"output-error": /* @__PURE__ */ jsx(XCircleIcon, { className: "size-4 text-red-600" }),
			"output-denied": /* @__PURE__ */ jsx(XCircleIcon, { className: "size-4 text-orange-600" })
		}[e], i[e]]
	});
};
const ToolHeader = (r) => {
	let i = c(24), a, s, l, d, p;
	i[0] === r ? (a = i[1], s = i[2], l = i[3], d = i[4], p = i[5]) : ({className: a, title: d, type: p, state: l, ...s} = r, i[0] = r, i[1] = a, i[2] = s, i[3] = l, i[4] = d, i[5] = p);
	let m;
	i[6] === a ? m = i[7] : (m = cn("flex w-full items-center justify-between gap-4 p-3", a), i[6] = a, i[7] = m);
	let g;
	i[8] === Symbol.for("react.memo_cache_sentinel") ? (g = /* @__PURE__ */ jsx(WrenchIcon, { className: "text-muted-foreground size-4" }), i[8] = g) : g = i[8];
	let _;
	i[9] !== d || i[10] !== p ? (_ = d ?? p.split("-").slice(1).join("-"), i[9] = d, i[10] = p, i[11] = _) : _ = i[11];
	let y;
	i[12] === _ ? y = i[13] : (y = /* @__PURE__ */ jsx("span", {
		className: "text-sm font-medium",
		children: _
	}), i[12] = _, i[13] = y);
	let b;
	i[14] === l ? b = i[15] : (b = getStatusBadge(l), i[14] = l, i[15] = b);
	let x;
	i[16] !== y || i[17] !== b ? (x = /* @__PURE__ */ jsxs("div", {
		className: "flex items-center gap-2",
		children: [
			g,
			y,
			b
		]
	}), i[16] = y, i[17] = b, i[18] = x) : x = i[18];
	let S;
	i[19] === Symbol.for("react.memo_cache_sentinel") ? (S = /* @__PURE__ */ jsx(ChevronDownIcon, { className: "text-muted-foreground size-4 transition-transform group-data-[state=open]:rotate-180" }), i[19] = S) : S = i[19];
	let C;
	return i[20] !== s || i[21] !== m || i[22] !== x ? (C = /* @__PURE__ */ jsxs(CollapsibleTrigger, {
		className: m,
		...s,
		children: [x, S]
	}), i[20] = s, i[21] = m, i[22] = x, i[23] = C) : C = i[23], C;
}, ToolContent = (r) => {
	let i = c(8), o, s;
	i[0] === r ? (o = i[1], s = i[2]) : ({className: o, ...s} = r, i[0] = r, i[1] = o, i[2] = s);
	let l;
	i[3] === o ? l = i[4] : (l = cn("data-[state=closed]:fade-out-0 data-[state=closed]:slide-out-to-top-2 data-[state=open]:slide-in-from-top-2 text-popover-foreground data-[state=closed]:animate-out data-[state=open]:animate-in outline-none", o), i[3] = o, i[4] = l);
	let u;
	return i[5] !== s || i[6] !== l ? (u = /* @__PURE__ */ jsx(CollapsibleContent, {
		className: l,
		...s
	}), i[5] = s, i[6] = l, i[7] = u) : u = i[7], u;
}, ToolInput = (r) => {
	let i = c(15), a, o, l;
	i[0] === r ? (a = i[1], o = i[2], l = i[3]) : ({className: a, input: o, ...l} = r, i[0] = r, i[1] = a, i[2] = o, i[3] = l);
	let d;
	i[4] === a ? d = i[5] : (d = cn("space-y-2 overflow-hidden p-4", a), i[4] = a, i[5] = d);
	let f;
	i[6] === Symbol.for("react.memo_cache_sentinel") ? (f = /* @__PURE__ */ jsx("h4", {
		className: "text-muted-foreground text-xs font-medium tracking-wide uppercase",
		children: "Parameters"
	}), i[6] = f) : f = i[6];
	let p;
	i[7] === o ? p = i[8] : (p = JSON.stringify(o, null, 2), i[7] = o, i[8] = p);
	let m;
	i[9] === p ? m = i[10] : (m = /* @__PURE__ */ jsx("div", {
		className: "bg-muted/50 rounded-md",
		children: /* @__PURE__ */ jsx(CodeBlock, {
			code: p,
			language: "json"
		})
	}), i[9] = p, i[10] = m);
	let h;
	return i[11] !== l || i[12] !== d || i[13] !== m ? (h = /* @__PURE__ */ jsxs("div", {
		className: d,
		...l,
		children: [f, m]
	}), i[11] = l, i[12] = d, i[13] = m, i[14] = h) : h = i[14], h;
}, ToolOutput = (r) => {
	let i = c(30), a, o, d, f;
	if (i[0] === r ? (a = i[1], o = i[2], d = i[3], f = i[4]) : ({className: a, output: d, errorText: o, ...f} = r, i[0] = r, i[1] = a, i[2] = o, i[3] = d, i[4] = f), !(d || o)) return null;
	let p = d, m;
	i[5] === p ? m = i[6] : (m = /* @__PURE__ */ jsx("div", { children: p }), i[5] = p, i[6] = m);
	let h = m;
	if (typeof d == "object" && !isValidElement(d)) {
		let e;
		i[7] === d ? e = i[8] : (e = JSON.stringify(d, null, 2), i[7] = d, i[8] = e);
		let r;
		i[9] === e ? r = i[10] : (r = /* @__PURE__ */ jsx(CodeBlock, {
			code: e,
			language: "json"
		}), i[9] = e, i[10] = r), h = r;
	} else if (typeof d == "string") {
		let e;
		i[11] === d ? e = i[12] : (e = /* @__PURE__ */ jsx(CodeBlock, {
			code: d,
			language: "json"
		}), i[11] = d, i[12] = e), h = e;
	}
	let g;
	i[13] === a ? g = i[14] : (g = cn("space-y-2 p-4", a), i[13] = a, i[14] = g);
	let _ = o ? "Error" : "Result", v;
	i[15] === _ ? v = i[16] : (v = /* @__PURE__ */ jsx("h4", {
		className: "text-muted-foreground text-xs font-medium tracking-wide uppercase",
		children: _
	}), i[15] = _, i[16] = v);
	let y = o ? "bg-destructive/10 text-destructive" : "bg-muted/50 text-foreground", b;
	i[17] === y ? b = i[18] : (b = cn("overflow-x-auto rounded-md text-xs [&_table]:w-full", y), i[17] = y, i[18] = b);
	let x;
	i[19] === o ? x = i[20] : (x = o && /* @__PURE__ */ jsx("div", { children: o }), i[19] = o, i[20] = x);
	let S;
	i[21] !== h || i[22] !== b || i[23] !== x ? (S = /* @__PURE__ */ jsxs("div", {
		className: b,
		children: [x, h]
	}), i[21] = h, i[22] = b, i[23] = x, i[24] = S) : S = i[24];
	let C;
	return i[25] !== f || i[26] !== g || i[27] !== v || i[28] !== S ? (C = /* @__PURE__ */ jsxs("div", {
		className: g,
		...f,
		children: [v, S]
	}), i[25] = f, i[26] = g, i[27] = v, i[28] = S, i[29] = C) : C = i[29], C;
};
export { Tool, ToolContent, ToolHeader, ToolInput, ToolOutput };
