import { defineComponent, shallowRef, watchEffect, computed, createVNode, Fragment } from 'vue';
import { CloseOutlined } from '@ant-design/icons-vue';
import '../../../utils/index.mjs';
import useConfigInject from '../../config-provider/src/hooks/useConfigInject.mjs';
import '../../wave/index.mjs';
import useStyle from '../style/index.mjs';
import ACheckableTag from './CheckableTag.mjs';
import { tagProps } from './props.mjs';
import { devWarning } from '../../../utils/log.mjs';
import { isPresetColor, isPresetStatusColor } from '../../../utils/color.mjs';
import { classNames } from '../../../utils/dom/class.mjs';
import Wave from '../../wave/src/Wave.mjs';

var ATag = /* @__PURE__ */ defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "ATag",
  inheritAttrs: false,
  props: tagProps(),
  CheckableTag: ACheckableTag,
  // 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") {
      devWarning(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",
      [`${prefixCls.value}-borderless`]: !props.bordered
    }));
    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", {
        ...attrs,
        "onClick": handleClick,
        "class": [tagClassName.value, attrs.class],
        "style": [tagStyle, attrs.style]
      }, [kids, renderCloseIcon()]);
      return wrapSSR(isNeedWave ? createVNode(Wave, null, {
        default: () => [tagNode]
      }) : tagNode);
    };
  }
});

export { ATag as default };
//# sourceMappingURL=Tag.mjs.map
