'use strict';

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

var vue = require('vue');
var CloseOutlined = require('@ant-design/icons-vue');
require('../hooks/index.js');
var classNames = require('../_util/classNames.js');
var index = require('../_util/vue-types/index.js');
var index$2 = require('../vc-wave/index.js');
var colors = require('../_util/colors.js');
var type = require('../_util/type.js');
var warning = require('../_util/warning.js');
var index$1 = require('./style/index.js');
var CheckableTag = require('./CheckableTag.js');
var useConfigInject = require('../config-provider/hooks/useConfigInject.js');

function _isSlot(s) {
  return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !vue.isVNode(s);
}
const tagProps = () => ({
  "prefixCls": String,
  "color": {
    type: String
  },
  "closable": {
    type: Boolean,
    default: false
  },
  "closeIcon": index.default.any,
  /** @deprecated `visible` will be removed in next major version. */
  "visible": {
    type: Boolean,
    default: void 0
  },
  "onClose": {
    type: Function
  },
  "onClick": type.eventType(),
  "onUpdate:visible": Function,
  "icon": index.default.any
});
const Tag = /* @__PURE__ */ vue.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.default("tag", props);
    const [wrapSSR, hashId] = index$1.default(prefixCls);
    const visible = vue.shallowRef(true);
    if (process.env.NODE_ENV !== "production") {
      warning.default(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(() => colors.isPresetColor(props.color) || colors.isPresetStatusColor(props.color));
    const tagClassName = vue.computed(() => classNames.default(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 ? vue.createVNode("span", {
            "class": `${prefixCls.value}-close-icon`,
            "onClick": handleCloseClick
          }, [closeIcon]) : vue.createVNode(CloseOutlined.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", vue.mergeProps(attrs, {
        "onClick": handleClick,
        "class": [tagClassName.value, attrs.class],
        "style": [tagStyle, attrs.style]
      }), [kids, renderCloseIcon()]);
      return wrapSSR(isNeedWave ? vue.createVNode(index$2.default, null, _isSlot(tagNode) ? tagNode : {
        default: () => [tagNode]
      }) : tagNode);
    };
  }
});
Tag.CheckableTag = CheckableTag.default;
Tag.install = function(app) {
  app.component(Tag.name, Tag);
  app.component(CheckableTag.default.name, CheckableTag.default);
  return app;
};

exports.CheckableTag = CheckableTag.default;
exports.default = Tag;
exports.tagProps = tagProps;
//# sourceMappingURL=index.js.map
