import { __assign, __rest } from "tslib";
import React, { forwardRef, useMemo, cloneElement } from "react";
import { IconBrokenEdit, IconBrokenSlash } from "@greenatom/icons";
import H from "../typography/H";
import P1 from "../typography/P1";
import { AvatarStyle, OnlineStatus, AvatarWrapper } from "./style";
export var Avatar = forwardRef(function (_a, ref) {
    var className = _a.className, text = _a.text, _b = _a.hoverIcon, hoverIcon = _b === void 0 ? React.createElement(IconBrokenEdit, null) : _b, icon = _a.icon, _c = _a.disabledIcon, disabledIcon = _c === void 0 ? React.createElement(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 = __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 = useMemo(function () {
        if (!text) {
            return "";
        }
        return text[0];
    }, [text]);
    return (React.createElement(AvatarWrapper, { className: className, "data-testid": testId },
        React.createElement(AvatarStyle, __assign({ onClick: handleClick, disabled: isDisabled, image: image, ref: ref, size: size, as: as }, props),
            !isDisabled &&
                hoverIcon &&
                cloneElement(hoverIcon, {
                    width: 16,
                    height: 16,
                    className: "edit"
                }),
            icon &&
                !image &&
                !initials &&
                !isDisabled &&
                cloneElement(icon, {
                    width: 16,
                    height: 16,
                    className: "avatar_icon"
                }),
            !isDisabled &&
                (!icon && !image && initials && (size === "xl" || size === "l") ? (React.createElement(H, { type: "libra", className: "text" }, initials)) : (React.createElement(P1, { className: "text", type: "cygnus" }, initials))),
            isDisabled &&
                disabledIcon &&
                cloneElement(disabledIcon, {
                    className: "disabled-icon",
                    width: 16,
                    height: 16
                })),
        !isDisabled && status && React.createElement(OnlineStatus, { status: status, size: size })));
});
Avatar.displayName = "Avatar";
