"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;exports.__esModule = true;exports.TokenDataTids = exports.Token = void 0;var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
var _react = _interopRequireDefault(require("react"));

var _decorators = require("../../lib/locale/decorators");
var _utils = require("../../lib/utils");
var _ThemeContext = require("../../lib/theming/ThemeContext");


var _CommonWrapper = require("../../internal/CommonWrapper");
var _Emotion = require("../../lib/theming/Emotion");

var _rootNode = require("../../lib/rootNode");
var _CloseButtonIcon = require("../../internal/CloseButtonIcon/CloseButtonIcon");

var _reactGetTextContent = require("../../lib/reactGetTextContent");
var _getVisualStateDataAttributes = require("../../internal/CommonWrapper/utils/getVisualStateDataAttributes");

var _Token2 = require("./Token.styles");

var _locale = require("./locale");
var _TokenView = require("./TokenView");var _dec, _class, _Token;






























var TokenDataTids = exports.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 = exports.Token = (_dec = (0, _decorators.locale)('Token', _locale.TokenLocaleHelper), (0, _rootNode.rootNode)(_class = _dec(_class = (_Token = /*#__PURE__*/function (_React$Component) {function Token() {var _this;for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {args[_key] = arguments[_key];}_this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;_this.
























































































    onRemoveClick = function (event) {
      var _this$props = _this.props,disabled = _this$props.disabled,_this$props$onRemove = _this$props.onRemove,onRemove = _this$props$onRemove === void 0 ? _utils.emptyHandler : _this$props$onRemove;

      if (disabled) {
        event.preventDefault();
        return;
      }

      onRemove(event);
    };return _this;}(0, _inheritsLoose2.default)(Token, _React$Component);var _proto = Token.prototype;_proto.render = function render() {var _this2 = this;return /*#__PURE__*/_react.default.createElement(_ThemeContext.ThemeContext.Consumer, null, function (theme) {_this2.theme = theme;return _this2.renderMain();});};_proto.renderMain = function renderMain() {var _this$props2 = this.props,size = _this$props2.size,children = _this$props2.children,isActive = _this$props2.isActive,error = _this$props2.error,warning = _this$props2.warning,disabled = _this$props2.disabled,ariaDescribedby = _this$props2['aria-describedby'],_this$props2$onClick = _this$props2.onClick,onClick = _this$props2$onClick === void 0 ? _utils.emptyHandler : _this$props2$onClick,_this$props2$onDouble = _this$props2.onDoubleClick,onDoubleClick = _this$props2$onDouble === void 0 ? _utils.emptyHandler : _this$props2$onDouble,_this$props2$onMouseE = _this$props2.onMouseEnter,onMouseEnter = _this$props2$onMouseE === void 0 ? _utils.emptyHandler : _this$props2$onMouseE,_this$props2$onMouseL = _this$props2.onMouseLeave,onMouseLeave = _this$props2$onMouseL === void 0 ? _utils.emptyHandler : _this$props2$onMouseL,_this$props2$onFocus = _this$props2.onFocus,onFocus = _this$props2$onFocus === void 0 ? _utils.emptyHandler : _this$props2$onFocus,_this$props2$onBlur = _this$props2.onBlur,onBlur = _this$props2$onBlur === void 0 ? _utils.emptyHandler : _this$props2$onBlur;var theme = this.theme;var removeButtonAriaLabel = this.locale.removeButtonAriaLabel + ' ' + (0, _reactGetTextContent.reactGetTextContent)(children);var icon = /*#__PURE__*/_react.default.createElement(_CloseButtonIcon.CloseButtonIcon, { side: 16, color: "inherit", colorHover: "inherit", "aria-label": removeButtonAriaLabel, tabbable: false });var classNames = (0, _Emotion.cx)(_Token2.styles.tokenIdle(theme), !isActive && !warning && !error && !disabled && _Token2.styles.tokenHover(theme), isActive && _Token2.styles.tokenActive(theme), warning && _Token2.styles.tokenWarning(theme), error && _Token2.styles.tokenError(theme), disabled && _Token2.styles.tokenDisabled(theme));var textholder = /*#__PURE__*/_react.default.createElement("span", { className: _Token2.styles.text() }, children);var closeButton = /*#__PURE__*/_react.default.createElement("span", { onClick: this.onRemoveClick, "data-tid": TokenDataTids.removeIcon }, icon);return /*#__PURE__*/_react.default.createElement(_CommonWrapper.CommonWrapper, (0, _extends2.default)({ rootNodeRef: this.setRootNode }, this.props, (0, _getVisualStateDataAttributes.getVisualStateDataAttributes)({ disabled: disabled })), /*#__PURE__*/_react.default.createElement(_TokenView.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));};return Token;}(_react.default.Component), _Token.__KONTUR_REACT_UI__ = 'Token', _Token.displayName = 'Token', _Token)) || _class) || _class);