import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import { defineComponent, computed, createVNode as _createVNode } from 'vue';
import classNames from '../_util/classNames';
import useConfigInject from '../config-provider/hooks/useConfigInject';
import useStyle from './style';
import PropTypes from '../_util/vue-types';
const checkableTagProps = () => ({
  prefixCls: String,
  disabled: Boolean,
  checked: {
    type: Boolean,
    default: undefined
  },
  onChange: {
    type: Function
  },
  onClick: {
    type: Function
  },
  'onUpdate:checked': Function,
  icon: PropTypes.any
});
const CheckableTag = defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: 'ACheckableTag',
  inheritAttrs: false,
  props: checkableTagProps(),
  // emits: ['update:checked', 'change', 'click'],
  setup(props, {
    slots,
    emit,
    attrs
  }) {
    const {
      prefixCls
    } = useConfigInject('tag', props);
    // Style
    const [wrapSSR, hashId] = useStyle(prefixCls);
    const handleClick = e => {
      if (props.disabled) {
        return;
      }
      const {
        checked
      } = props;
      emit('update:checked', !checked);
      emit('change', !checked);
      emit('click', e);
    };
    const cls = computed(() => classNames(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(_createVNode("span", _objectSpread(_objectSpread({}, attrs), {}, {
        "class": [cls.value, attrs.class],
        "onClick": handleClick
      }), [icon, _createVNode("span", null, [(_b = slots.default) === null || _b === void 0 ? void 0 : _b.call(slots)])]));
    };
  }
});
export default CheckableTag;