import { jsx as e, jsxs as r, Fragment as b } from "react/jsx-runtime";
import { ChevronsUpDownIcon as y } from "lucide-react";
import { Avatar as D, AvatarImage as j, AvatarFallback as C } from "../atoms/avatar.js";
import { Button as M } from "../atoms/button.js";
import { DropdownMenu as I, DropdownMenuTrigger as k, DropdownMenuContent as z, DropdownMenuLabel as A, DropdownMenuSeparator as U } from "../atoms/dropdown-menu.js";
import { cn as a } from "../../../lib/utils.js";
function B(n) {
  return n.split(" ").filter(Boolean).map((t) => t[0]).join("").slice(0, 2).toUpperCase();
}
const F = {
  sm: "size-9",
  lg: "size-10"
};
function p({
  name: n,
  avatarUrl: t,
  avatarSize: o,
  avatarClassName: s,
  badge: i,
  secondaryContent: l,
  hideDetails: m = !1
}) {
  const c = B(n) || "U";
  return /* @__PURE__ */ r(b, { children: [
    /* @__PURE__ */ r("div", { className: "relative shrink-0", children: [
      /* @__PURE__ */ r(D, { className: a(F[o], "rounded-lg"), children: [
        t && /* @__PURE__ */ e(j, { alt: n, src: t }),
        /* @__PURE__ */ e(
          C,
          {
            className: a(
              "rounded-lg bg-purple-600 font-semibold text-white text-xs",
              s
            ),
            children: c
          }
        )
      ] }),
      i
    ] }),
    /* @__PURE__ */ r(
      "div",
      {
        className: a(
          "flex min-w-0 flex-1 flex-col items-start gap-px text-left leading-tight",
          m && "hidden"
        ),
        children: [
          /* @__PURE__ */ e("span", { className: "w-full truncate font-semibold text-foreground text-sm", children: n }),
          l
        ]
      }
    )
  ] });
}
function G({
  name: n,
  email: t,
  avatarUrl: o,
  avatarSize: s = "sm",
  avatarClassName: i,
  badge: l,
  menuBadge: m,
  secondary: c,
  menuSecondary: h,
  compact: f = !1,
  children: g,
  dropdownSide: w = "top",
  dropdownAlign: N = "end",
  className: x
}) {
  const u = n ?? "User";
  let d = null;
  c !== void 0 ? d = c : t && (d = /* @__PURE__ */ e("span", { className: "w-full truncate text-muted-foreground text-xs", children: t }));
  const v = h === void 0 ? d : h;
  return g ? /* @__PURE__ */ r(I, { children: [
    /* @__PURE__ */ r(
      k,
      {
        render: /* @__PURE__ */ e(
          M,
          {
            "aria-label": `${u} menu`,
            className: a(
              "h-auto w-full cursor-pointer justify-start gap-3 overflow-visible rounded-lg px-1.5 py-2 transition-colors",
              "hover:bg-accent hover:text-accent-foreground",
              "data-open:bg-accent data-open:text-accent-foreground",
              f && "size-10 justify-center px-0",
              x
            ),
            variant: "ghost"
          }
        ),
        children: [
          /* @__PURE__ */ e(
            p,
            {
              avatarClassName: i,
              avatarSize: s,
              avatarUrl: o,
              badge: l,
              hideDetails: f,
              name: u,
              secondaryContent: d
            }
          ),
          !f && /* @__PURE__ */ e(y, { className: "ml-auto size-4 shrink-0 text-muted-foreground" })
        ]
      }
    ),
    /* @__PURE__ */ r(
      z,
      {
        align: N,
        className: "w-(--anchor-width) min-w-56",
        side: w,
        sideOffset: 4,
        children: [
          /* @__PURE__ */ e(A, { className: "p-0 font-normal", children: /* @__PURE__ */ e("div", { className: "flex items-center gap-3 px-3 py-2.5", children: /* @__PURE__ */ e(
            p,
            {
              avatarClassName: i,
              avatarSize: s,
              avatarUrl: o,
              badge: m ?? l,
              name: u,
              secondaryContent: v
            }
          ) }) }),
          /* @__PURE__ */ e(U, {}),
          g
        ]
      }
    )
  ] }) : /* @__PURE__ */ e(
    "div",
    {
      className: a(
        "flex w-full items-center gap-3 rounded-lg px-1.5 py-2",
        x
      ),
      children: /* @__PURE__ */ e(
        p,
        {
          avatarClassName: i,
          avatarSize: s,
          avatarUrl: o,
          badge: l,
          hideDetails: f,
          name: u,
          secondaryContent: d
        }
      )
    }
  );
}
export {
  G as UserNav
};
