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; }

import * as React from 'react';
import { View } from 'remax/one';
import classNames from 'classnames';
import { getPrefixCls } from './../common';
var prefixCls = 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 = classNames(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(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: classNames((_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);
};

export default Tag;