import { jsxs, jsx } from 'react/jsx-runtime';
import { forwardRef } from 'react';
import { c as cn } from './utils-BJnb9o5c.js';
import { Avatar as Avatar$1, AvatarImage, AvatarFallback, AvatarBadge, AvatarGroupCount, AvatarGroup } from './primitives/Avatar.js';
import { TooltipProvider, Tooltip, TooltipTrigger, TooltipContent } from './primitives/Tooltip.js';

const STATUS_COLOR_MAP = {
  online: "bg-emerald-500 dark:bg-emerald-400",
  idle: "bg-amber-500 dark:bg-amber-400",
  offline: "bg-gray-400 dark:bg-gray-500"
};
const SIDE_MAP = {
  top: "top",
  bottom: "bottom",
  left: "left",
  right: "right",
  auto: "bottom"
};
const XL_CLASSES = "data-[size=lg]:size-16 [&>[data-slot=avatar-badge]]:size-4 [&>[data-slot=avatar-fallback]]:text-lg";

function getInitials(name) {
  if (!name) return "";
  return name.split(/\s+/).slice(0, 2).map((word) => word.charAt(0).toUpperCase()).join("");
}
function cyrb53(str, seed = 0) {
  let h1 = 3735928559 ^ seed;
  let h2 = 1103547991 ^ seed;
  for (let i = 0; i < str.length; i++) {
    const ch = str.charCodeAt(i);
    h1 = Math.imul(h1 ^ ch, 2654435761);
    h2 = Math.imul(h2 ^ ch, 1597334677);
  }
  h1 = Math.imul(h1 ^ h1 >>> 16, 2246822507) ^ Math.imul(h2 ^ h2 >>> 13, 3266489909);
  h2 = Math.imul(h2 ^ h2 >>> 16, 2246822507) ^ Math.imul(h1 ^ h1 >>> 13, 3266489909);
  return 4294967296 * (2097151 & h2) + (h1 >>> 0);
}
function getAvatarColorStyle(seed) {
  if (!seed) return void 0;
  const hue = cyrb53(seed) % 360;
  return {
    backgroundColor: `oklch(var(--avatar-l) var(--avatar-c) ${hue})`,
    color: "var(--avatar-fg)"
  };
}

const Avatar = forwardRef(
  ({
    user,
    status,
    showTooltip = false,
    tooltipProps,
    size = "default",
    className,
    ...otherProps
  }, ref) => {
    const initials = getInitials(user?.name);
    const isXl = size === "xl";
    const primitiveSize = isXl ? "lg" : size;
    const seed = user?.id != null ? String(user.id) : user?.email?.trim().toLowerCase() || user?.name;
    const avatarElement = /* @__PURE__ */ jsxs(
      Avatar$1,
      {
        ref,
        size: primitiveSize,
        className: cn(isXl && XL_CLASSES, className),
        ...otherProps,
        children: [
          user?.imageUrl && /* @__PURE__ */ jsx(AvatarImage, { src: user.imageUrl, alt: user?.name ?? "" }),
          /* @__PURE__ */ jsx(AvatarFallback, { style: getAvatarColorStyle(seed), children: initials }),
          status && /* @__PURE__ */ jsx(AvatarBadge, { className: cn(STATUS_COLOR_MAP[status]) })
        ]
      }
    );
    const tooltipContent = tooltipProps?.content ?? (showTooltip ? user?.name : null);
    if (tooltipContent) {
      const side = SIDE_MAP[tooltipProps?.position ?? "auto"] ?? "bottom";
      return /* @__PURE__ */ jsx(TooltipProvider, { delayDuration: 0, children: /* @__PURE__ */ jsxs(Tooltip, { children: [
        /* @__PURE__ */ jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "inline-flex", children: avatarElement }) }),
        /* @__PURE__ */ jsx(TooltipContent, { side, children: tooltipContent })
      ] }) });
    }
    return avatarElement;
  }
);
Avatar.displayName = "Avatar";
const AvatarNamespace = Object.assign(Avatar, {
  Group: AvatarGroup,
  GroupCount: AvatarGroupCount
});

export { AvatarNamespace as A };
//# sourceMappingURL=Avatar-DxRDQDjh.js.map
