var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        if (typeof b !== "function" && b !== null)
            throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import React from 'react';
import { locale } from '../../lib/locale/decorators.js';
import { emptyHandler } from '../../lib/utils.js';
import { ThemeContext } from '../../lib/theming/ThemeContext.js';
import { CommonWrapper } from '../../internal/CommonWrapper/index.js';
import { rootNode } from '../../lib/rootNode/index.js';
import { CloseButtonIcon } from '../../internal/CloseButtonIcon/CloseButtonIcon.js';
import { reactGetTextContent } from '../../lib/reactGetTextContent.js';
import { getVisualStateDataAttributes } from '../../internal/CommonWrapper/utils/getVisualStateDataAttributes.js';
import { withRenderEnvironment } from '../../lib/renderEnvironment/index.js';
import { getStyles } from './Token.styles.js';
import { TokenLocaleHelper } from './locale/index.js';
import { TokenView } from './TokenView.js';
export var TokenDataTids = {
    root: 'Token__root',
    removeIcon: 'Token__removeIcon',
};
/** Токены — это значение заданного формата внутри поля ввода. Например, номера телефонов, почты, ИНН, СНИЛС, статусы, группы и другие.
 *
 * Используется ак значение внутри [TokenInput](https://tech.skbkontur.ru/kontur-ui/?path=/docs/react-ui_input-data-tokeninput-tokeninput--docs).
 */
var Token = /** @class */ (function (_super) {
    __extends(Token, _super);
    function Token() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.onRemoveClick = function (event) {
            var _a = _this.props, disabled = _a.disabled, _b = _a.onRemove, onRemove = _b === void 0 ? emptyHandler : _b;
            if (disabled) {
                event.preventDefault();
                return;
            }
            onRemove(event);
        };
        return _this;
    }
    Token.prototype.render = function () {
        var _this = this;
        this.styles = getStyles(this.emotion);
        return (React.createElement(ThemeContext.Consumer, null, function (theme) {
            _this.theme = theme;
            return _this.renderMain();
        }));
    };
    Token.prototype.renderMain = function () {
        var _a = this.props, size = _a.size, children = _a.children, isActive = _a.isActive, error = _a.error, warning = _a.warning, disabled = _a.disabled, ariaDescribedby = _a["aria-describedby"], _b = _a.onClick, onClick = _b === void 0 ? emptyHandler : _b, _c = _a.onDoubleClick, onDoubleClick = _c === void 0 ? emptyHandler : _c, _d = _a.onMouseEnter, onMouseEnter = _d === void 0 ? emptyHandler : _d, _e = _a.onMouseLeave, onMouseLeave = _e === void 0 ? emptyHandler : _e, _f = _a.onFocus, onFocus = _f === void 0 ? emptyHandler : _f, _g = _a.onBlur, onBlur = _g === void 0 ? emptyHandler : _g;
        var theme = this.theme;
        var removeButtonAriaLabel = this.locale.removeButtonAriaLabel + ' ' + reactGetTextContent(children);
        var icon = (React.createElement(CloseButtonIcon, { side: 16, color: "inherit", colorHover: "inherit", "aria-label": removeButtonAriaLabel, tabbable: false }));
        var classNames = this.cx(this.styles.tokenIdle(theme), !isActive && !warning && !error && !disabled && this.styles.tokenHover(theme), isActive && this.styles.tokenActive(theme), warning && this.styles.tokenWarning(theme), error && this.styles.tokenError(theme), disabled && this.styles.tokenDisabled(theme));
        var textholder = React.createElement("span", { className: this.styles.text() }, children);
        var closeButton = (React.createElement("span", { onClick: this.onRemoveClick, "data-tid": TokenDataTids.removeIcon }, icon));
        return (React.createElement(CommonWrapper, __assign({ rootNodeRef: this.setRootNode }, this.props, getVisualStateDataAttributes({ disabled: disabled })),
            React.createElement(TokenView, { className: classNames, size: size, closeButton: closeButton, "data-tid": TokenDataTids.root, "aria-describedby": ariaDescribedby, onClick: onClick, onDoubleClick: onDoubleClick, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, onFocus: onFocus, onBlur: onBlur }, textholder)));
    };
    Token.__KONTUR_REACT_UI__ = 'Token';
    Token.displayName = 'Token';
    Token = __decorate([
        withRenderEnvironment,
        rootNode,
        locale('Token', TokenLocaleHelper)
    ], Token);
    return Token;
}(React.Component));
export { Token };
//# sourceMappingURL=Token.js.map