import { isVNode, defineComponent, shallowRef, watchEffect, computed, createVNode, Fragment, mergeProps } from 'vue';
import { CloseOutlined } from '@ant-design/icons-vue';
import '../hooks/index.mjs';
import classNames from '../_util/classNames.mjs';
import PropTypes from '../_util/vue-types/index.mjs';
import Wave from '../vc-wave/index.mjs';
import { isPresetColor, isPresetStatusColor } from '../_util/colors.mjs';
import { eventType } from '../_util/type.mjs';
import warning from '../_util/warning.mjs';
import useStyle from './style/index.mjs';
import CheckableTag from './CheckableTag.mjs';
import useConfigInject from '../config-provider/hooks/useConfigInject.mjs';

function _isSlot(s) {
  return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !isVNode(s);
}
const tagProps = () => ({
  "prefixCls": String,
  "color": {
    type: String
  },
  "closable": {
    type: Boolean,
    default: false
  },
  "closeIcon": PropTypes.any,
  /** @deprecated `visible` will be removed in next major version. */
  "visible": {
    type: Boolean,
    default: void 0
  },
  "onClose": {
    type: Function
  },
  "onClick": eventType(),
  "onUpdate:visible": Function,
  "icon": PropTypes.any
});
const Tag = /* @__PURE__ */ defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "ATag",
  inheritAttrs: false,
  props: tagProps(),
  // emits: ['update:visible', 'close'],
  slots: Object,
  setup(props, {
    slots,
    emit,
    attrs
  }) {
    const {
      prefixCls,
      direction
    } = useConfigInject("tag", props);
    const [wrapSSR, hashId] = useStyle(prefixCls);
    const visible = shallowRef(true);
    if (process.env.NODE_ENV !== "production") {
      warning(props.visible === void 0, "Tag", '`visible` is deprecated, please use `<Tag v-show="visible" />` instead.');
    }
    watchEffect(() => {
      if (props.visible !== void 0)
        visible.value = props.visible;
    });
    const handleCloseClick = (e) => {
      e.stopPropagation();
      emit("update:visible", false);
      emit("close", e);
      if (e.defaultPrevented)
        return;
      if (props.visible === void 0)
        visible.value = false;
    };
    const isInternalColor = computed(() => isPresetColor(props.color) || isPresetStatusColor(props.color));
    const tagClassName = computed(() => classNames(prefixCls.value, hashId.value, {
      [`${prefixCls.value}-${props.color}`]: isInternalColor.value,
      [`${prefixCls.value}-has-color`]: props.color && !isInternalColor.value,
      [`${prefixCls.value}-hidden`]: !visible.value,
      [`${prefixCls.value}-rtl`]: direction.value === "rtl"
    }));
    const handleClick = (e) => {
      emit("click", e);
    };
    return () => {
      var _a, _b, _c;
      const {
        icon = (_a = slots.icon) == null ? void 0 : _a.call(slots),
        color,
        closeIcon = (_b = slots.closeIcon) == null ? void 0 : _b.call(slots),
        closable = false
      } = props;
      const renderCloseIcon = () => {
        if (closable) {
          return closeIcon ? createVNode("span", {
            "class": `${prefixCls.value}-close-icon`,
            "onClick": handleCloseClick
          }, [closeIcon]) : createVNode(CloseOutlined, {
            "class": `${prefixCls.value}-close-icon`,
            "onClick": handleCloseClick
          }, null);
        }
        return null;
      };
      const tagStyle = {
        backgroundColor: color && !isInternalColor.value ? color : void 0
      };
      const iconNode = icon || null;
      const children = (_c = slots.default) == null ? void 0 : _c.call(slots);
      const kids = iconNode ? createVNode(Fragment, null, [iconNode, createVNode("span", null, [children])]) : children;
      const isNeedWave = props.onClick !== void 0;
      const tagNode = createVNode("span", mergeProps(attrs, {
        "onClick": handleClick,
        "class": [tagClassName.value, attrs.class],
        "style": [tagStyle, attrs.style]
      }), [kids, renderCloseIcon()]);
      return wrapSSR(isNeedWave ? createVNode(Wave, null, _isSlot(tagNode) ? tagNode : {
        default: () => [tagNode]
      }) : tagNode);
    };
  }
});
Tag.CheckableTag = CheckableTag;
Tag.install = function(app) {
  app.component(Tag.name, Tag);
  app.component(CheckableTag.name, CheckableTag);
  return app;
};

export { CheckableTag, Tag as default, tagProps };
//# sourceMappingURL=index.mjs.map
