var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
import { jsx as _jsx } from "react/jsx-runtime";
import * as React from "react";
import { cn } from "@utils";
import { avatarVariants, avatarImageVariants, avatarFallbackVariants } from "./avatarVariants";
/**
 * Avatar component for displaying user profile images with fallback support
 */
export const Avatar = React.forwardRef((_a, ref) => {
    var { className, img, label, size = "md", alt, abbreviate = true } = _a, props = __rest(_a, ["className", "img", "label", "size", "alt", "abbreviate"]);
    const [error, setError] = React.useState(false);
    // Generate initials from label for fallback
    const getInitials = (name) => {
        if (!name) {
            return "";
        }
        const nameParts = name.split(" ").filter(Boolean);
        if (nameParts.length === 1) {
            return nameParts[0].charAt(0).toUpperCase();
        }
        return (nameParts[0].charAt(0) + nameParts[nameParts.length - 1].charAt(0)).toUpperCase();
    };
    if (!label) {
        return null;
    }
    return (_jsx("div", Object.assign({ ref: ref, className: cn(avatarVariants({ size }), className) }, props, { children: img && !error ? (_jsx("img", { src: img, alt: alt || label, loading: "lazy", className: cn(avatarImageVariants()), onError: () => setError(true) })) : (_jsx("div", { className: cn(avatarFallbackVariants()), children: _jsx("span", { children: abbreviate ? getInitials(label) : label }) })) })));
});
Avatar.displayName = "Avatar";
//# sourceMappingURL=avatar.js.map