import { jsxs, jsx } from 'react/jsx-runtime';
import { forwardRef } from 'react';
import { c as cn } from './utils-DdHUxIdC.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("");
}

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

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