"use client";
import { useStudio as e } from "../../providers/StudioProvider.js";
import { cn as t } from "../../lib/utils.js";
import { Tooltip as n, TooltipContent as r, TooltipTrigger as i } from "../ui/tooltip.js";
import { useEffect as a, useState as o } from "react";
import { jsx as s, jsxs as c } from "react/jsx-runtime";
import { ChevronDownIcon as l, ChevronUpIcon as u, ExternalLinkIcon as d, FolderClosedIcon as f, FolderOpenIcon as p } from "lucide-react";
//#region src/components/loopstack-elements/link.tsx
var m = "loopstack:embed:resize", h = {
	pending: "text-muted-foreground",
	success: "text-green-600",
	failure: "text-red-600"
}, g = /^\/workflows\/([a-zA-Z0-9_-]+)$/, _ = ({ className: _, href: v, label: y, status: b = "pending", embed: x, defaultExpanded: S }) => {
	let { router: C } = e(), [w, T] = o(S ?? !1), [E, D] = o(0), O = y || (() => {
		if (!v) return "";
		try {
			return new URL(v).hostname.replace("www.", "");
		} catch {
			return v;
		}
	})(), k = v?.match(g)?.[1] ?? null, A = x === !0 && k != null ? C.getEmbedWorkflow(k) : null;
	return a(() => {
		if (!k || !w) return;
		let e = (e) => {
			if (e.origin !== window.location.origin) return;
			let t = e.data;
			if (t?.type !== m || t?.workflowId !== k) return;
			let n = t?.height;
			typeof n == "number" && n > 0 && D(n);
		};
		return window.addEventListener("message", e), () => window.removeEventListener("message", e);
	}, [k, w]), /* @__PURE__ */ c("div", {
		className: t("not-prose flex w-full cursor-pointer flex-col", _),
		onClick: () => A && T((e) => !e),
		children: [/* @__PURE__ */ c("div", {
			className: "flex w-full items-center gap-1.5 py-1",
			children: [
				/* @__PURE__ */ c(n, { children: [/* @__PURE__ */ s(i, {
					asChild: !0,
					children: /* @__PURE__ */ s("span", {
						className: t("flex shrink-0 items-center", h[b]),
						children: s(w ? p : f, { className: "size-4" })
					})
				}), /* @__PURE__ */ s(r, {
					side: "top",
					children: w ? "Collapse" : "Expand"
				})] }),
				/* @__PURE__ */ s("span", {
					className: t("min-w-0 flex-1 truncate text-sm", w ? "font-medium" : "text-muted-foreground"),
					children: O
				}),
				/* @__PURE__ */ c("div", {
					className: "flex shrink-0 items-center gap-1",
					children: [v && /* @__PURE__ */ s("a", {
						href: v,
						target: "_blank",
						rel: "noopener noreferrer",
						onClick: (e) => e.stopPropagation(),
						className: "text-muted-foreground hover:text-foreground flex items-center justify-center transition-colors",
						children: /* @__PURE__ */ s(d, { className: "size-3.5" })
					}), A && s(w ? u : l, { className: "text-muted-foreground size-3.5" })]
				})
			]
		}), w && A && /* @__PURE__ */ s("div", {
			className: "mt-2 border-t",
			children: /* @__PURE__ */ s("iframe", {
				src: A,
				className: "w-full overflow-hidden border-0",
				style: { height: `${E}px` },
				scrolling: "no",
				title: O
			})
		})]
	});
};
//#endregion
export { _ as default };
