"use strict";

exports.__esModule = true;
exports.default = void 0;
var _babelRuntimeJsxStyleTransform = require("babel-runtime-jsx-style-transform");
var _tslib = require("tslib");
var _react = _interopRequireWildcard(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _view = _interopRequireDefault(require("../view"));
var _createChildren = _interopRequireDefault(require("./create-children"));
var _utils = require("../utils");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
var Tag = function (props, ref) {
  var _classNames;
  var _props$prefix = props.prefix,
    prefix = _props$prefix === void 0 ? 'mt-' : _props$prefix,
    _props$size = props.size,
    size = _props$size === void 0 ? 'medium' : _props$size,
    _props$type = props.type,
    type = _props$type === void 0 ? 'normal' : _props$type,
    _props$disabled = props.disabled,
    disabled = _props$disabled === void 0 ? false : _props$disabled,
    _props$onClick = props.onClick,
    onClick = _props$onClick === void 0 ? function () {} : _props$onClick,
    _props$style = props.style,
    style = _props$style === void 0 ? {} : _props$style,
    children = props.children,
    color = props.color,
    textColorProp = props.textColor,
    className = props.className,
    others = (0, _tslib.__rest)(props, ["prefix", "size", "type", "disabled", "onClick", "style", "children", "color", "textColor", "className"]);
  var cssType = type === 'normal' ? 'outline' : 'solid';
  var tagCls = (0, _classnames.default)(className, prefix + "tag", prefix + "tag--" + size, prefix + "tag--readonly-" + size, prefix + "tag--normal-" + cssType, (_classNames = {}, _classNames[prefix + "tag--normal-" + cssType + "-disabled"] = disabled, _classNames));
  var textColor = textColorProp;
  if ((0, _utils.isString)(color) && !textColor) {
    if (type === 'primary') {
      textColor = '#fff';
    } else {
      textColor = color;
    }
  }
  var newStyle = Object.assign(Object.assign(Object.assign({}, (0, _utils.isString)(color) && type === 'primary' ? {
    backgroundColor: color
  } : {
    borderColor: color
  }), (0, _utils.isString)(textColor) ? {
    color: textColor
  } : null), style);
  return /*#__PURE__*/(0, _react.createElement)(_view.default, _extends({}, others, {
    ref: ref,
    className: tagCls,
    onClick: function handleClick(e) {
      if (disabled) {
        return;
      }
      if (onClick) {
        onClick(e);
      }
    },
    style: (0, _babelRuntimeJsxStyleTransform.rpx2vw4style)(newStyle)
  }), (0, _createChildren.default)(children, {
    textCls: prefix + "tag-font--" + size,
    iconCls: prefix + "tag-font--" + size
  }, prefix, size));
};
Tag.displayName = 'Tag';
var _default = /*#__PURE__*/(0, _react.forwardRef)(Tag);
exports.default = _default;