"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
var _vue = require("vue");
var _classNames = _interopRequireDefault(require("../_util/classNames"));
var _useConfigInject = _interopRequireDefault(require("../config-provider/hooks/useConfigInject"));
var _style = _interopRequireDefault(require("./style"));
var _vueTypes = _interopRequireDefault(require("../_util/vue-types"));
const checkableTagProps = () => ({
  prefixCls: String,
  disabled: Boolean,
  checked: {
    type: Boolean,
    default: undefined
  },
  onChange: {
    type: Function
  },
  onClick: {
    type: Function
  },
  'onUpdate:checked': Function,
  icon: _vueTypes.default.any
});
const CheckableTag = (0, _vue.defineComponent)({
  compatConfig: {
    MODE: 3
  },
  name: 'ACheckableTag',
  inheritAttrs: false,
  props: checkableTagProps(),
  // emits: ['update:checked', 'change', 'click'],
  setup(props, {
    slots,
    emit,
    attrs
  }) {
    const {
      prefixCls
    } = (0, _useConfigInject.default)('tag', props);
    // Style
    const [wrapSSR, hashId] = (0, _style.default)(prefixCls);
    const handleClick = e => {
      if (props.disabled) {
        return;
      }
      const {
        checked
      } = props;
      emit('update:checked', !checked);
      emit('change', !checked);
      emit('click', e);
    };
    const cls = (0, _vue.computed)(() => (0, _classNames.default)(prefixCls.value, hashId.value, {
      [`${prefixCls.value}-checkable`]: true,
      [`${prefixCls.value}-checkable-checked`]: props.checked,
      [`${prefixCls.value}-checkable-disabled`]: props.disabled
    }));
    return () => {
      var _a, _b;
      const {
        icon = (_a = slots.icon) === null || _a === void 0 ? void 0 : _a.call(slots)
      } = props;
      return wrapSSR((0, _vue.createVNode)("span", (0, _objectSpread2.default)((0, _objectSpread2.default)({}, attrs), {}, {
        "class": [cls.value, attrs.class],
        "onClick": handleClick
      }), [icon, (0, _vue.createVNode)("span", null, [(_b = slots.default) === null || _b === void 0 ? void 0 : _b.call(slots)])]));
    };
  }
});
var _default = exports.default = CheckableTag;