import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import React, { useState } from 'react';
import cx from 'classnames';
import { ConfigContext } from '../config-provider/context';
import Image from '../image';
import { Icons } from '../components';
import Tag from './tag';
var ChooseLine = 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 = _objectWithoutProperties(props, ["checked", "help", "onChange", "disabled", "imageProps", "className"]);

  var _React$useContext = React.useContext(ConfigContext),
      getPrefixClassName = _React$useContext.getPrefixClassName;

  var tagPrefix = getPrefixClassName('tag');

  var _useState = useState(checked),
      _useState2 = _slicedToArray(_useState, 2),
      status = _useState2[0],
      setStatus = _useState2[1];

  var checkAbleTagcls = cx((_cx = {}, _defineProperty(_cx, "".concat(tagPrefix, "-has-help"), help), _defineProperty(_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.createElement("div", {
    onClick: clickEvent,
    className: cx("".concat(tagPrefix, "-check-wrap"), {
      checked: status
    })
  }, /*#__PURE__*/React.createElement(Tag, Object.assign({}, reset, {
    disabled: disabled,
    className: checkAbleTagcls
  }), imageProps && /*#__PURE__*/React.createElement("div", {
    className: "".concat(tagPrefix, "-img")
  }, /*#__PURE__*/React.createElement(Image, Object.assign({
    preview: false
  }, imageProps))), props.children, help && /*#__PURE__*/React.createElement("div", {
    className: "".concat(tagPrefix, "-help")
  }, help)), /*#__PURE__*/React.createElement("div", {
    className: "".concat(tagPrefix, "-check-wrap-icon")
  }, /*#__PURE__*/React.createElement(ChooseLine, null)));
};

CheckAbleTag.displayName = 'CheckAbleTag';
export default CheckAbleTag;