'use strict';

var jsxRuntime = require('react/jsx-runtime');
var React = require('react');
var utils = require('./utils-BhM0B89p.js');
var primitives_Avatar = require('./primitives/Avatar.js');
var primitives_Tooltip = require('./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("");
}

const Avatar = React.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 avatarElement = /* @__PURE__ */ jsxRuntime.jsxs(
      primitives_Avatar.Avatar,
      {
        ref,
        size: primitiveSize,
        className: utils.cn(isXl && XL_CLASSES, className),
        ...otherProps,
        children: [
          user?.imageUrl && /* @__PURE__ */ jsxRuntime.jsx(primitives_Avatar.AvatarImage, { src: user.imageUrl, alt: user?.name ?? "" }),
          /* @__PURE__ */ jsxRuntime.jsx(primitives_Avatar.AvatarFallback, { children: initials }),
          status && /* @__PURE__ */ jsxRuntime.jsx(primitives_Avatar.AvatarBadge, { className: utils.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__ */ jsxRuntime.jsx(primitives_Tooltip.TooltipProvider, { delayDuration: 0, children: /* @__PURE__ */ jsxRuntime.jsxs(primitives_Tooltip.Tooltip, { children: [
        /* @__PURE__ */ jsxRuntime.jsx(primitives_Tooltip.TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "inline-flex", children: avatarElement }) }),
        /* @__PURE__ */ jsxRuntime.jsx(primitives_Tooltip.TooltipContent, { side, children: tooltipContent })
      ] }) });
    }
    return avatarElement;
  }
);
Avatar.displayName = "Avatar";
const AvatarNamespace = Object.assign(Avatar, {
  Group: primitives_Avatar.AvatarGroup,
  GroupCount: primitives_Avatar.AvatarGroupCount
});

exports.AvatarNamespace = AvatarNamespace;
//# sourceMappingURL=Avatar-nG7vhAUS.js.map
