"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

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

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));

var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));

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

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

var _context = require("../config-provider/context");

var _image = _interopRequireDefault(require("../image"));

var _components = require("../components");

var _tag = _interopRequireDefault(require("./tag"));

var ChooseLine = _components.Icons.ChooseLine;

var CheckAbleTag = function CheckAbleTag(props) {
  var _cx;

  var checked = props.checked,
      help = props.help,
      onChange = props.onChange,
      disabled = props.disabled,
      imageProps = props.imageProps,
      className = props.className,
      reset = (0, _objectWithoutProperties2.default)(props, ["checked", "help", "onChange", "disabled", "imageProps", "className"]);

  var _React$useContext = _react.default.useContext(_context.ConfigContext),
      getPrefixClassName = _React$useContext.getPrefixClassName;

  var tagPrefix = getPrefixClassName('tag');

  var _useState = (0, _react.useState)(checked),
      _useState2 = (0, _slicedToArray2.default)(_useState, 2),
      status = _useState2[0],
      setStatus = _useState2[1];

  var checkAbleTagcls = (0, _classnames.default)((_cx = {}, (0, _defineProperty2.default)(_cx, "".concat(tagPrefix, "-has-help"), help), (0, _defineProperty2.default)(_cx, "".concat(tagPrefix, "-has-image"), imageProps && imageProps.src), _cx), className);

  if (typeof checked !== 'undefined' && checked !== status) {
    setStatus(checked);
  }

  var clickEvent = function clickEvent() {
    if (disabled) return;
    onChange === null || onChange === void 0 ? void 0 : onChange(props.children, !status);

    if (typeof checked === 'undefined') {
      setStatus(!status);
    }
  };

  return /*#__PURE__*/_react.default.createElement("div", {
    onClick: clickEvent,
    className: (0, _classnames.default)("".concat(tagPrefix, "-check-wrap"), {
      checked: status
    })
  }, /*#__PURE__*/_react.default.createElement(_tag.default, Object.assign({}, reset, {
    disabled: disabled,
    className: checkAbleTagcls
  }), imageProps && /*#__PURE__*/_react.default.createElement("div", {
    className: "".concat(tagPrefix, "-img")
  }, /*#__PURE__*/_react.default.createElement(_image.default, Object.assign({
    preview: false
  }, imageProps))), props.children, help && /*#__PURE__*/_react.default.createElement("div", {
    className: "".concat(tagPrefix, "-help")
  }, help)), /*#__PURE__*/_react.default.createElement("div", {
    className: "".concat(tagPrefix, "-check-wrap-icon")
  }, /*#__PURE__*/_react.default.createElement(ChooseLine, null)));
};

CheckAbleTag.displayName = 'CheckAbleTag';
var _default = CheckAbleTag;
exports.default = _default;