import { cn as e } from "../../../lib/utils.js";
import { ScrollArea as t, ScrollBar as n } from "../../../components/ui/scroll-area.js";
import r from "../../../components/dynamic-form/MarkdownContent.js";
import { ReactFlowProvider as i } from "../../../node_modules/@xyflow/react/dist/esm/index.js";
import { Tabs as a, TabsContent as o, TabsList as s, TabsTrigger as c } from "../../../components/ui/tabs.js";
import l from "../../debug/components/ConfigFlowViewer.js";
import "../../debug/index.js";
import { jsx as u, jsxs as d } from "react/jsx-runtime";
import { Loader2 as f } from "lucide-react";
import { Prism as p } from "react-syntax-highlighter";
import { vscDarkPlus as m } from "react-syntax-highlighter/dist/esm/styles/prism";
//#region src/features/code-explorer/components/FileContentViewer.tsx
var h = new Set([
	".ico",
	".svg",
	".png",
	".jpg",
	".jpeg",
	".gif",
	".webp",
	".woff",
	".woff2",
	".ttf",
	".eot",
	".bin",
	".exe",
	".dll",
	".so",
	".dylib"
]);
function g(e) {
	let t = e.includes(".") ? e.slice(e.lastIndexOf(".")).toLowerCase() : "";
	return h.has(t);
}
var _ = {
	".ts": "typescript",
	".tsx": "tsx",
	".js": "javascript",
	".jsx": "jsx",
	".mjs": "javascript",
	".cjs": "javascript",
	".json": "json",
	".jsonc": "json",
	".md": "markdown",
	".mdx": "markdown",
	".css": "css",
	".scss": "scss",
	".sass": "sass",
	".less": "less",
	".html": "html",
	".htm": "html",
	".xml": "xml",
	".yaml": "yaml",
	".yml": "yaml",
	".toml": "toml",
	".sh": "bash",
	".bash": "bash",
	".zsh": "bash",
	".fish": "bash",
	".txt": "plaintext",
	".log": "plaintext",
	".env": "plaintext",
	".gitignore": "plaintext",
	".dockerfile": "dockerfile",
	".dockerignore": "plaintext"
};
function v(e) {
	return _[e.includes(".") ? e.slice(e.lastIndexOf(".")).toLowerCase() : ""] ?? "plaintext";
}
function y({ selectedFile: h, content: _, workflowConfig: y = null, isLoading: b = !1, className: x }) {
	if (!h) return /* @__PURE__ */ u("div", {
		className: e("flex flex-1 items-center justify-center bg-background", x),
		children: /* @__PURE__ */ u("p", {
			className: "text-sm text-muted-foreground",
			children: "Select a tab to view its content"
		})
	});
	let S = g(h.name), C = _ != null, w = _ ?? "";
	if (S && !C) return /* @__PURE__ */ u("div", {
		className: e("flex flex-1 flex-col rounded-lg border bg-background", x),
		children: /* @__PURE__ */ u("div", {
			className: "flex flex-1 items-center justify-center p-8",
			children: /* @__PURE__ */ u("p", {
				className: "text-sm text-muted-foreground",
				children: "Binary file — preview not available"
			})
		})
	});
	if (!C && !b) return /* @__PURE__ */ u("div", {
		className: e("flex flex-1 flex-col rounded-lg border bg-background", x),
		children: /* @__PURE__ */ u("div", {
			className: "flex flex-1 items-center justify-center p-8",
			children: /* @__PURE__ */ u("p", {
				className: "text-sm text-destructive",
				children: "Error loading file content"
			})
		})
	});
	if (b) return /* @__PURE__ */ u("div", {
		className: e("flex flex-1 flex-col rounded-lg border bg-background", x),
		children: /* @__PURE__ */ u("div", {
			className: "flex justify-center p-8",
			children: /* @__PURE__ */ u(f, { className: "h-6 w-6 animate-spin text-muted-foreground" })
		})
	});
	let T = v(h.name), E = T === "markdown" || h.name.endsWith(".md") || h.name.endsWith(".mdx"), D = (T === "yaml" || h.name.endsWith(".yaml") || h.name.endsWith(".yml")) && y !== null, O = (e) => /* @__PURE__ */ d(t, {
		className: "h-full w-full",
		children: [/* @__PURE__ */ u(p, {
			language: T,
			style: m,
			customStyle: {
				margin: 0,
				padding: "1rem",
				fontSize: "13px",
				overflow: "visible",
				minWidth: "max-content",
				width: "100%"
			},
			showLineNumbers: !0,
			PreTag: "div",
			codeTagProps: { style: { fontFamily: "inherit" } },
			children: e
		}), /* @__PURE__ */ u(n, { orientation: "horizontal" })]
	});
	return /* @__PURE__ */ u("div", {
		className: e("flex h-full flex-col overflow-hidden rounded-lg border bg-background", x),
		children: E && w ? /* @__PURE__ */ d(a, {
			defaultValue: "rendered",
			className: "flex h-full flex-col overflow-hidden",
			children: [
				/* @__PURE__ */ d(s, {
					className: "shrink-0 mx-2 mt-2",
					children: [/* @__PURE__ */ u(c, {
						value: "rendered",
						children: "Rendered"
					}), /* @__PURE__ */ u(c, {
						value: "unrendered",
						children: "Unrendered"
					})]
				}),
				/* @__PURE__ */ u(o, {
					value: "rendered",
					className: "flex-1 min-h-0 overflow-hidden mt-2",
					children: /* @__PURE__ */ u(t, {
						className: "h-full",
						children: /* @__PURE__ */ u("div", {
							className: "p-4",
							children: /* @__PURE__ */ u(r, { content: w })
						})
					})
				}),
				/* @__PURE__ */ u(o, {
					value: "unrendered",
					className: "flex-1 min-h-0 overflow-hidden mt-0",
					children: O(w)
				})
			]
		}) : D && y ? /* @__PURE__ */ d(a, {
			defaultValue: "code",
			className: "flex h-full flex-col overflow-hidden",
			children: [
				/* @__PURE__ */ d(s, {
					className: "shrink-0 mx-2 mt-2",
					children: [/* @__PURE__ */ u(c, {
						value: "code",
						children: "Code"
					}), /* @__PURE__ */ u(c, {
						value: "flow",
						children: "Flow Diagram"
					})]
				}),
				/* @__PURE__ */ u(o, {
					value: "code",
					className: "flex-1 min-h-0 overflow-hidden mt-0",
					children: O(w)
				}),
				/* @__PURE__ */ u(o, {
					value: "flow",
					className: "flex-1 min-h-0 overflow-hidden mt-0",
					children: /* @__PURE__ */ u("div", {
						className: "h-full w-full",
						children: /* @__PURE__ */ u(i, { children: /* @__PURE__ */ u(l, { config: y }) })
					})
				})
			]
		}) : O(w)
	});
}
//#endregion
export { y as FileContentViewer };
