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