"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var React = _interopRequireWildcard(require("react"));

var _one = require("remax/one");

var _classnames = _interopRequireDefault(require("classnames"));

var _common = require("./../common");

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 _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var prefixCls = (0, _common.getPrefixCls)('tag');

var Tag = function Tag(props) {
  var _classNames;

  var color = props.color,
      plain = props.plain,
      size = props.size,
      block = props.block,
      className = props.className,
      style = props.style,
      children = props.children,
      onTap = props.onTap;
  var classes = (0, _classnames.default)(prefixCls, (_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-plain"), plain), _defineProperty(_classNames, "".concat(prefixCls, "-small"), size === 'small'), _defineProperty(_classNames, "".concat(prefixCls, "-large"), size === 'large'), _defineProperty(_classNames, "".concat(prefixCls, "-block"), block), _defineProperty(_classNames, "".concat(prefixCls, "-").concat(color), color), _classNames), className);
  return /*#__PURE__*/React.createElement(_one.View, {
    className: classes,
    style: style,
    onTap: onTap
  }, children);
};

Tag.CheckableTag = function (props) {
  var _classNames2;

  var className = props.className,
      checked = props.checked,
      checkedColor = props.checkedColor,
      _props$style = props.style,
      style = _props$style === void 0 ? {} : _props$style,
      disabled = props.disabled,
      onChange = props.onChange,
      children = props.children;
  var height = style.height;
  var tagHeight = height;

  if (typeof height === 'string') {
    if (height.includes('px')) {
      tagHeight = Number(height.slice(0, -2));
    } else {
      tagHeight = Number(height);
    }
  }

  var tagStyle = undefined;

  if (height) {
    tagStyle = Object.assign(Object.assign({}, style), {
      lineHeight: "".concat(tagHeight - 4, "px")
    });
  }

  var handleChange = function handleChange() {
    if (disabled) {
      return;
    }

    onChange === null || onChange === void 0 ? void 0 : onChange(!checked);
  };

  return /*#__PURE__*/React.createElement(Tag, Object.assign({
    size: "large"
  }, props, {
    className: (0, _classnames.default)((_classNames2 = {}, _defineProperty(_classNames2, "".concat(prefixCls, "-checkable"), true), _defineProperty(_classNames2, "".concat(prefixCls, "-checked"), checked), _defineProperty(_classNames2, "".concat(prefixCls, "-").concat(checkedColor), checked && checkedColor), _defineProperty(_classNames2, "".concat(prefixCls, "-disabled"), disabled), _classNames2), className),
    style: tagStyle,
    onTap: handleChange
  }), children);
};

var _default = Tag;
exports.default = _default;