import { useWorkflow } from "../../../hooks/useWorkflows.js";
import { cn } from "../../../lib/utils.js";
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "../../../components/ui/collapsible.js";
import { Tooltip, TooltipContent, TooltipTrigger } from "../../../components/ui/tooltip.js";
import { SidebarMenuButton, SidebarMenuItem, SidebarMenuSub } from "../../../components/ui/sidebar.js";
import { c } from "react/compiler-runtime";
import React from "react";
import { jsx, jsxs } from "react/jsx-runtime";
import { ChevronRight, Clock, Loader2, Play, Wrench } from "lucide-react";
import { format } from "date-fns";
var WorkflowHistoryItem_default = (x) => {
	let S = c(19), { workflowId: C, workflow: w } = x, T = useWorkflow(C), E = T.data?.history;
	if (T.isLoading) {
		let e;
		return S[0] === Symbol.for("react.memo_cache_sentinel") ? (e = /* @__PURE__ */ jsx(SidebarMenuItem, { children: /* @__PURE__ */ jsxs(SidebarMenuButton, {
			className: "opacity-50",
			children: [/* @__PURE__ */ jsx(Loader2, { className: "h-3 w-3 animate-spin" }), /* @__PURE__ */ jsx("span", {
				className: "text-sm",
				children: "Loading..."
			})]
		}) }), S[0] = e) : e = S[0], e;
	}
	if (!E?.length) return null;
	let D;
	S[1] === Symbol.for("react.memo_cache_sentinel") ? (D = /* @__PURE__ */ jsx(Play, { className: "text-primary h-3.5 w-3.5 fill-current" }), S[1] = D) : D = S[1];
	let O = w.title ?? w.blockName, k;
	S[2] === O ? k = S[3] : (k = /* @__PURE__ */ jsx("span", {
		className: "truncate text-sm",
		children: O
	}), S[2] = O, S[3] = k);
	let A;
	S[4] === Symbol.for("react.memo_cache_sentinel") ? (A = /* @__PURE__ */ jsx(ChevronRight, { className: "text-muted-foreground ml-auto h-3.5 w-3.5 transition-transform group-data-[state=open]/collapsible:rotate-90" }), S[4] = A) : A = S[4];
	let j;
	S[5] === k ? j = S[6] : (j = /* @__PURE__ */ jsx(CollapsibleTrigger, {
		asChild: !0,
		children: /* @__PURE__ */ jsxs(SidebarMenuButton, {
			className: "group/trigger font-medium",
			children: [
				D,
				k,
				A
			]
		})
	}), S[5] = k, S[6] = j);
	let M;
	S[7] === Symbol.for("react.memo_cache_sentinel") ? (M = /* @__PURE__ */ jsx("div", { className: "from-primary/60 via-primary/30 to-muted/20 absolute top-7 bottom-3 left-1.75 w-0.5 rounded-full bg-linear-to-b" }), S[7] = M) : M = S[7];
	let N;
	S[8] === Symbol.for("react.memo_cache_sentinel") ? (N = /* @__PURE__ */ jsx("div", {
		className: "relative z-10 flex shrink-0 items-center justify-center",
		children: /* @__PURE__ */ jsx("div", { className: "border-primary/60 bg-primary/20 flex h-4 w-4 items-center justify-center rounded-full border-2" })
	}), S[8] = N) : N = S[8];
	let P;
	S[9] === Symbol.for("react.memo_cache_sentinel") ? (P = /* @__PURE__ */ jsxs("div", {
		className: "group/entry relative flex gap-3 py-1 pl-0",
		children: [N, /* @__PURE__ */ jsx("div", {
			className: "flex min-w-0 flex-1 items-center gap-1.5",
			children: /* @__PURE__ */ jsx("span", {
				className: "bg-muted text-foreground w-fit truncate rounded px-1.5 py-0.5 font-mono text-xs font-medium",
				children: "start"
			})
		})]
	}), S[9] = P) : P = S[9];
	let F;
	if (S[10] !== E) {
		let e;
		S[12] === E.length ? e = S[13] : (e = (e, h) => {
			console.log(e);
			let g = e.data?.transition, _ = Object.keys(e.data?.tools ?? {}), v = h === E.length - 1, y = e.data?.place ?? g?.to ?? "unknown", b = g?.id;
			return /* @__PURE__ */ jsxs("div", {
				className: "group/entry relative flex gap-3 py-1 pl-0",
				children: [/* @__PURE__ */ jsx("div", {
					className: "relative z-10 flex shrink-0 items-center justify-center",
					children: /* @__PURE__ */ jsx("div", {
						className: cn("flex h-4 w-4 items-center justify-center rounded-full border-2 transition-all", v ? "border-primary bg-primary shadow-primary/40 shadow-sm" : "border-muted-foreground/30 bg-background"),
						children: v && /* @__PURE__ */ jsx("div", { className: "bg-primary-foreground h-1.5 w-1.5 animate-pulse rounded-full" })
					})
				}), /* @__PURE__ */ jsxs("div", {
					className: "flex min-w-0 flex-1 flex-col gap-0.5",
					children: [/* @__PURE__ */ jsxs("div", {
						className: "flex items-baseline gap-1.5",
						children: [/* @__PURE__ */ jsx("span", {
							className: cn("w-fit truncate rounded px-1.5 py-0.5 font-mono text-xs font-medium", v ? "bg-primary/15 text-primary" : "bg-muted/60 text-muted-foreground"),
							children: y
						}), b && /* @__PURE__ */ jsxs("span", {
							className: "text-muted-foreground truncate text-[10px] italic",
							children: [
								"(via ",
								b,
								")"
							]
						})]
					}), /* @__PURE__ */ jsxs("div", {
						className: "text-muted-foreground flex items-center gap-2 text-[10px]",
						children: [_.length > 0 && /* @__PURE__ */ jsxs(Tooltip, { children: [/* @__PURE__ */ jsx(TooltipTrigger, {
							asChild: !0,
							children: /* @__PURE__ */ jsxs("div", {
								className: "flex cursor-default items-center gap-0.5",
								children: [/* @__PURE__ */ jsx(Wrench, { className: "h-3 w-3" }), /* @__PURE__ */ jsx("span", {
									className: "tabular-nums",
									children: _.length
								})]
							})
						}), /* @__PURE__ */ jsxs(TooltipContent, {
							side: "right",
							className: "max-w-48",
							children: [/* @__PURE__ */ jsx("p", {
								className: "text-xs font-medium",
								children: "Tools used:"
							}), /* @__PURE__ */ jsx("p", {
								className: "text-muted-foreground text-[11px]",
								children: _.join(", ")
							})]
						})] }), /* @__PURE__ */ jsxs("div", {
							className: "flex items-center gap-0.5",
							children: [/* @__PURE__ */ jsx(Clock, { className: "h-3 w-3" }), /* @__PURE__ */ jsx("span", {
								className: "tabular-nums",
								children: format(new Date(e.timestamp), "HH:mm:ss")
							})]
						})]
					})]
				})]
			}, e.version);
		}, S[12] = E.length, S[13] = e), F = E.map(e), S[10] = E, S[11] = F;
	} else F = S[11];
	let I;
	S[14] === F ? I = S[15] : (I = /* @__PURE__ */ jsx(CollapsibleContent, { children: /* @__PURE__ */ jsx(SidebarMenuSub, {
		className: "ml-2 border-none pl-0",
		children: /* @__PURE__ */ jsxs("div", {
			className: "relative py-2",
			children: [
				M,
				P,
				F
			]
		})
	}) }), S[14] = F, S[15] = I);
	let L;
	return S[16] !== I || S[17] !== j ? (L = /* @__PURE__ */ jsx(Collapsible, {
		defaultOpen: !0,
		className: "group/collapsible",
		children: /* @__PURE__ */ jsxs(SidebarMenuItem, { children: [j, I] })
	}), S[16] = I, S[17] = j, S[18] = L) : L = S[18], L;
};
export { WorkflowHistoryItem_default as default };
