(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports", "tslib", "react", "@greenatom/icons", "../typography/H", "../typography/P1", "./style"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    exports.Avatar = void 0;
    var tslib_1 = require("tslib");
    var react_1 = (0, tslib_1.__importStar)(require("react"));
    var icons_1 = require("@greenatom/icons");
    var H_1 = (0, tslib_1.__importDefault)(require("../typography/H"));
    var P1_1 = (0, tslib_1.__importDefault)(require("../typography/P1"));
    var style_1 = require("./style");
    exports.Avatar = (0, react_1.forwardRef)(function (_a, ref) {
        var className = _a.className, text = _a.text, _b = _a.hoverIcon, hoverIcon = _b === void 0 ? react_1.default.createElement(icons_1.IconBrokenEdit, null) : _b, icon = _a.icon, _c = _a.disabledIcon, disabledIcon = _c === void 0 ? react_1.default.createElement(icons_1.IconBrokenSlash, null) : _c, image = _a.image, onClick = _a.onClick, isDisabled = _a.isDisabled, status = _a.status, _d = _a.size, size = _d === void 0 ? "xl" : _d, _e = _a.as, as = _e === void 0 ? "button" : _e, _f = _a.testId, testId = _f === void 0 ? "avatar" : _f, props = (0, tslib_1.__rest)(_a, ["className", "text", "hoverIcon", "icon", "disabledIcon", "image", "onClick", "isDisabled", "status", "size", "as", "testId"]);
        var handleClick = function (event) {
            onClick === null || onClick === void 0 ? void 0 : onClick(event);
        };
        var initials = (0, react_1.useMemo)(function () {
            if (!text) {
                return "";
            }
            return text[0];
        }, [text]);
        return (react_1.default.createElement(style_1.AvatarWrapper, { className: className, "data-testid": testId },
            react_1.default.createElement(style_1.AvatarStyle, (0, tslib_1.__assign)({ onClick: handleClick, disabled: isDisabled, image: image, ref: ref, size: size, as: as }, props),
                !isDisabled &&
                    hoverIcon &&
                    (0, react_1.cloneElement)(hoverIcon, {
                        width: 16,
                        height: 16,
                        className: "edit"
                    }),
                icon &&
                    !image &&
                    !initials &&
                    !isDisabled &&
                    (0, react_1.cloneElement)(icon, {
                        width: 16,
                        height: 16,
                        className: "avatar_icon"
                    }),
                !isDisabled &&
                    (!icon && !image && initials && (size === "xl" || size === "l") ? (react_1.default.createElement(H_1.default, { type: "libra", className: "text" }, initials)) : (react_1.default.createElement(P1_1.default, { className: "text", type: "cygnus" }, initials))),
                isDisabled &&
                    disabledIcon &&
                    (0, react_1.cloneElement)(disabledIcon, {
                        className: "disabled-icon",
                        width: 16,
                        height: 16
                    })),
            !isDisabled && status && react_1.default.createElement(style_1.OnlineStatus, { status: status, size: size })));
    });
    exports.Avatar.displayName = "Avatar";
});
