import { cn as e } from "../../../lib/utils.js";
import { i as t, n, t as r } from "../../../tooltip-34vRSwJG.js";
import { Loader as i } from "../atoms/loader.js";
import { SidebarMenuAction as a, SidebarMenuButton as o, SidebarMenuItem as s } from "../atoms/sidebar.js";
import { ConfirmPopover as c } from "./confirm-popover.js";
import { useRef as l, useState as u } from "react";
import { jsx as d, jsxs as f } from "react/jsx-runtime";
import { Trash2Icon as p } from "lucide-react";
//#region lib/components/ui/molecules/chat-history-item.tsx
function m({ title: m, isActive: h, isStreaming: g = !1, href: _, linkComponent: v, onSelect: y, onDelete: b, deleteIcon: x }) {
	let [S, C] = u(!1), w = l(null), T = (e) => {
		if (!e) {
			C(!1);
			return;
		}
		w.current && w.current.scrollWidth > w.current.offsetWidth && C(!0);
	}, E = e("py-2.5 group-hover/menu-item:bg-sidebar-accent group-hover/menu-item:text-sidebar-accent-foreground", (b || g) && "pr-8");
	return /* @__PURE__ */ f(s, { children: [/* @__PURE__ */ f(r, {
		onOpenChange: T,
		open: S,
		children: [/* @__PURE__ */ d(t, {
			render: _ ? /* @__PURE__ */ d(o, {
				className: E,
				isActive: h,
				render: v ? /* @__PURE__ */ d(v, {
					onClick: y,
					to: _
				}) : /* @__PURE__ */ d("a", {
					href: _,
					onClick: y
				})
			}) : /* @__PURE__ */ d(o, {
				className: E,
				isActive: h,
				onClick: y
			}),
			children: /* @__PURE__ */ d("span", {
				className: "truncate",
				ref: w,
				children: m
			})
		}), /* @__PURE__ */ d(n, {
			side: "right",
			children: m
		})]
	}), g ? /* @__PURE__ */ d(a, {
		"aria-hidden": "true",
		className: "pointer-events-none",
		tabIndex: -1,
		children: /* @__PURE__ */ d(i, {
			className: "border-sidebar-foreground/25 border-t-sidebar-foreground",
			size: "sm",
			variant: "circular"
		})
	}) : b && /* @__PURE__ */ d(c, {
		confirmLabel: "Delete",
		description: "This action cannot be undone.",
		onConfirm: b,
		side: "right",
		title: "Delete this chat?",
		children: /* @__PURE__ */ d(a, {
			"aria-label": `Delete "${m}"`,
			className: "hover:bg-secondary hover:text-secondary-foreground",
			showOnHover: !0,
			children: x ?? /* @__PURE__ */ d(p, { className: "size-3.5" })
		})
	})] });
}
//#endregion
export { m as ChatHistoryItem };
