import { cn as e } from "../../../lib/utils.js";
import { Button as t } from "../../../components/ui/button.js";
import { DropdownMenu as n, DropdownMenuContent as r, DropdownMenuItem as i, DropdownMenuSeparator as a, DropdownMenuTrigger as o } from "../../../components/ui/dropdown-menu.js";
import { ScrollArea as s, ScrollBar as c } from "../../../components/ui/scroll-area.js";
import { getFileIcon as l } from "../utils/fileIcons.js";
import { ContextMenu as u, ContextMenuContent as d, ContextMenuItem as f, ContextMenuSeparator as p, ContextMenuTrigger as m } from "../../../components/ui/context-menu.js";
import { useEffect as h, useRef as g } from "react";
import { jsx as _, jsxs as v } from "react/jsx-runtime";
import { ClipboardCopy as y, MoreHorizontal as b, X as x, XCircle as S } from "lucide-react";
//#region src/features/code-explorer/components/FileTabsBarBase.tsx
function C({ openFiles: C, selectedFile: w, selectFile: T, closeFile: E, closeAll: D, closeOthers: O, closeToLeft: k, closeToRight: A }) {
	let j = g(null), M = g(C.length);
	if (h(() => {
		if (C.length > M.current && j.current) {
			let e = j.current.closest("[data-slot=\"scroll-area-viewport\"]");
			e && requestAnimationFrame(() => {
				e.scrollTo({
					left: e.scrollWidth,
					behavior: "smooth"
				});
			});
		}
		M.current = C.length;
	}, [C.length]), h(() => {
		if (w && j.current) {
			let e = j.current.querySelector(`[data-tab-path="${w.path}"]`);
			e && requestAnimationFrame(() => {
				e.scrollIntoView({
					behavior: "smooth",
					block: "nearest",
					inline: "nearest"
				});
			});
		}
	}, [w]), C.length === 0) return null;
	let N = (e) => {
		T(e);
	}, P = (e, t) => {
		e.stopPropagation(), E(t);
	}, F = (e) => {
		navigator.clipboard.writeText(e).catch((e) => {
			console.error("Failed to copy path:", e);
		});
	};
	return /* @__PURE__ */ v("div", {
		className: "shrink-0 border-b bg-muted/50 flex items-center overflow-hidden",
		children: [/* @__PURE__ */ v(s, {
			className: "flex-1 min-w-0",
			children: [/* @__PURE__ */ _("div", {
				ref: j,
				className: "flex h-9 items-center",
				style: { width: "max-content" },
				children: C.map((n) => {
					let r = l(n.name), i = w?.path === n.path, a = C.findIndex((e) => e.path === n.path), o = a > 0, s = a < C.length - 1;
					return /* @__PURE__ */ v(u, { children: [/* @__PURE__ */ _(m, {
						asChild: !0,
						children: /* @__PURE__ */ v("button", {
							type: "button",
							"data-tab-path": n.path,
							onClick: () => N(n),
							className: e("group relative flex h-9 min-w-[140px] max-w-[280px] shrink-0 items-center gap-2 border-r border-border/50 px-3 text-sm transition-all", "hover:bg-muted/70", i ? "bg-background text-foreground border-b-2 border-b-primary shadow-sm" : "text-muted-foreground bg-muted/30"),
							"aria-selected": i,
							"aria-label": `Tab: ${n.name}`,
							children: [
								/* @__PURE__ */ _(r, {
									className: "h-3.5 w-3.5 shrink-0",
									"aria-hidden": !0
								}),
								/* @__PURE__ */ _("span", {
									className: "truncate flex-1 text-left font-medium",
									children: n.name
								}),
								/* @__PURE__ */ _(t, {
									variant: "ghost",
									size: "icon",
									className: e("h-5 w-5 shrink-0 rounded opacity-0 group-hover:opacity-100 transition-opacity", "hover:bg-destructive/10 hover:text-destructive", i && "opacity-70"),
									onClick: (e) => P(e, n),
									"aria-label": `Close ${n.name}`,
									children: /* @__PURE__ */ _(x, { className: "h-3.5 w-3.5" })
								})
							]
						})
					}), /* @__PURE__ */ v(d, {
						className: "min-w-[180px]",
						children: [
							/* @__PURE__ */ _(f, {
								onClick: () => E(n),
								children: "Close"
							}),
							/* @__PURE__ */ _(f, {
								onClick: () => O(n),
								disabled: C.length <= 1,
								children: "Close Others"
							}),
							/* @__PURE__ */ _(f, {
								onClick: () => k(n),
								disabled: !o,
								children: "Close to the Left"
							}),
							/* @__PURE__ */ _(f, {
								onClick: () => A(n),
								disabled: !s,
								children: "Close to the Right"
							}),
							/* @__PURE__ */ _(p, {}),
							/* @__PURE__ */ _(f, {
								onClick: D,
								children: "Close All"
							}),
							/* @__PURE__ */ _(p, {}),
							/* @__PURE__ */ v(f, {
								onClick: () => F(n.path),
								children: [/* @__PURE__ */ _(y, { className: "h-4 w-4" }), "Copy Path"]
							})
						]
					})] }, n.path);
				})
			}), /* @__PURE__ */ _(c, { orientation: "horizontal" })]
		}), /* @__PURE__ */ _("div", {
			className: "shrink-0 border-l border-border/50 bg-muted/30 h-9 flex items-center",
			children: /* @__PURE__ */ v(n, { children: [/* @__PURE__ */ _(o, {
				asChild: !0,
				children: /* @__PURE__ */ _(t, {
					variant: "ghost",
					size: "icon",
					className: "h-9 w-9 rounded-none text-muted-foreground hover:bg-muted/70 hover:text-foreground",
					"aria-label": "Tab actions",
					children: /* @__PURE__ */ _(b, { className: "h-4 w-4" })
				})
			}), /* @__PURE__ */ v(r, {
				align: "end",
				className: "min-w-[180px]",
				children: [
					/* @__PURE__ */ _(i, {
						onClick: () => w && E(w),
						disabled: !w,
						children: "Close Active Tab"
					}),
					/* @__PURE__ */ _(i, {
						onClick: () => w && O(w),
						disabled: !w || C.length <= 1,
						children: "Close Other Tabs"
					}),
					/* @__PURE__ */ _(a, {}),
					/* @__PURE__ */ v(i, {
						onClick: D,
						children: [/* @__PURE__ */ _(S, { className: "h-4 w-4" }), "Close All Tabs"]
					})
				]
			})] })
		})]
	});
}
//#endregion
export { C as FileTabsBarBase };
