(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/P2", "../Avatar", "./style"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var tslib_1 = require("tslib");
    var react_1 = (0, tslib_1.__importStar)(require("react"));
    var icons_1 = require("@greenatom/icons");
    var P2_1 = (0, tslib_1.__importDefault)(require("../typography/P2"));
    var Avatar_1 = require("../Avatar");
    var style_1 = require("./style");
    var FONT_MAPPING = {
        s: "cetus",
        xs: "musca",
        m: "corvus"
    };
    var Tag = (0, react_1.forwardRef)(function (_a, ref) {
        var children = _a.children, className = _a.className, avatarProps = _a.avatarProps, isClosable = _a.isClosable, leadIcon = _a.leadIcon, isPressed = _a.isPressed, as = _a.as, isDisabled = _a.isDisabled, _b = _a.closeIcon, closeIcon = _b === void 0 ? react_1.default.createElement(icons_1.IconBrokenCloseCircle, null) : _b, _c = _a.size, size = _c === void 0 ? "m" : _c, onClickClose = _a.onClickClose, onClick = _a.onClick, _d = _a.testId, testId = _d === void 0 ? "tag" : _d, props = (0, tslib_1.__rest)(_a, ["children", "className", "avatarProps", "isClosable", "leadIcon", "isPressed", "as", "isDisabled", "closeIcon", "size", "onClickClose", "onClick", "testId"]);
        var handleClick = function (event) {
            onClick && !isDisabled && onClick(event);
            //  TODO check release
        };
        var renderLeadIcon = function () {
            if (leadIcon) {
                return (react_1.default.createElement(style_1.LeadIconWrapper, { className: "beforeSVG" }, leadIcon));
            }
            return null;
        };
        var renderCloseIcon = function () {
            if (closeIcon && isClosable) {
                return (isClosable && (react_1.default.createElement(style_1.CloseIconWrapper, { onClick: handleClickClose, size: size }, closeIcon)));
            }
            return null;
        };
        var handleClickClose = function (e) {
            e.preventDefault();
            e.stopPropagation();
            onClickClose && !isDisabled && onClickClose(e);
        };
        return (react_1.default.createElement(style_1.TagWrapper, (0, tslib_1.__assign)({ className: className, isPressed: isPressed, as: as, isClosable: isClosable, isDisabled: isDisabled, size: size, avatarProps: avatarProps, onClick: handleClick, ref: ref, "data-testid": testId }, props),
            renderLeadIcon(),
            avatarProps && (size === "m" || size === "s" || !size) && (react_1.default.createElement(Avatar_1.Avatar, (0, tslib_1.__assign)({ className: "tag__avatar", size: "s", isDisabled: isDisabled }, avatarProps, { as: "div" }))),
            react_1.default.createElement(P2_1.default, { type: FONT_MAPPING[size || "m"] || "corvus", className: "placeholder" }, children),
            renderCloseIcon()));
    });
    Tag.displayName = "Tag";
    exports.default = Tag;
});
