'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var vue = require('vue');
var iconsVue = require('@ant-design/icons-vue');
require('../../../utils/index.cjs');
var useConfigInject = require('../../config-provider/src/hooks/useConfigInject.cjs');
require('../../wave/index.cjs');
var index = require('../style/index.cjs');
var CheckableTag = require('./CheckableTag.cjs');
var props = require('./props.cjs');
var log = require('../../../utils/log.cjs');
var color = require('../../../utils/color.cjs');
var _class = require('../../../utils/dom/class.cjs');
var Wave = require('../../wave/src/Wave.cjs');

var ATag = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "ATag",
  inheritAttrs: false,
  props: props.tagProps(),
  CheckableTag: CheckableTag.default,
  // emits: ['update:visible', 'close'],
  slots: Object,
  setup(props, {
    slots,
    emit,
    attrs
  }) {
    const {
      prefixCls,
      direction
    } = useConfigInject.default("tag", props);
    const [wrapSSR, hashId] = index.default(prefixCls);
    const visible = vue.shallowRef(true);
    if (process.env.NODE_ENV !== "production") {
      log.devWarning(props.visible === void 0, "Tag", '`visible` is deprecated, please use `<Tag v-show="visible" />` instead.');
    }
    vue.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 = vue.computed(() => color.isPresetColor(props.color) || color.isPresetStatusColor(props.color));
    const tagClassName = vue.computed(() => _class.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 ? vue.createVNode("span", {
            "class": `${prefixCls.value}-close-icon`,
            "onClick": handleCloseClick
          }, [closeIcon]) : vue.createVNode(iconsVue.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 ? vue.createVNode(vue.Fragment, null, [iconNode, vue.createVNode("span", null, [children])]) : children;
      const isNeedWave = props.onClick !== void 0;
      const tagNode = vue.createVNode("span", {
        ...attrs,
        "onClick": handleClick,
        "class": [tagClassName.value, attrs.class],
        "style": [tagStyle, attrs.style]
      }, [kids, renderCloseIcon()]);
      return wrapSSR(isNeedWave ? vue.createVNode(Wave.default, null, {
        default: () => [tagNode]
      }) : tagNode);
    };
  }
});

exports.default = ATag;
//# sourceMappingURL=Tag.cjs.map
