"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const vue = require("vue");
const comp = require("../../ui/src/comp.js");
const XEUtils = require("xe-utils");
require("../../ui/index.js");
const config = require("../../../../@vxe-ui/core/es/src/config.js");
const useFns = require("../../../../@vxe-ui/core/es/src/useFns.js");
const event = require("../../../../@vxe-ui/core/es/src/event.js");
const index_esm = require("../../../../@vxe-ui/core/es/index.esm.js");
const icon = require("../../../../@vxe-ui/core/es/src/icon.js");
const VxeTagComponent = comp.defineVxeComponent({
  name: "VxeTag",
  props: {
    border: {
      type: Boolean,
      default: () => config.getConfig().tag.border
    },
    visible: {
      type: Boolean,
      default: null
    },
    status: String,
    title: [String, Number],
    icon: String,
    closeIcon: {
      type: String,
      default: () => config.getConfig().tag.closeIcon
    },
    content: [String, Number],
    round: Boolean,
    closable: {
      type: Boolean,
      default: () => config.getConfig().tag.closable
    },
    color: String,
    loading: Boolean,
    size: {
      type: String,
      default: () => config.getConfig().tag.size || config.getConfig().size
    }
  },
  emits: [
    "click",
    "dblclick",
    "close",
    "update:visible"
  ],
  setup(props, context) {
    const { slots, emit } = context;
    const xID = XEUtils.uniqueId();
    const { computeSize } = useFns.useSize(props);
    const refElem = vue.ref();
    const reactData = vue.reactive({
      showTag: props.visible !== false
    });
    const refMaps = {
      refElem
    };
    const computeMaps = {};
    const $xeTag = {
      xID,
      props,
      context,
      reactData,
      getRefMaps: () => refMaps,
      getComputeMaps: () => computeMaps
    };
    const dispatchEvent = (type, params, evnt) => {
      emit(type, event.createEvent(evnt, { $tag: $xeTag }, params));
    };
    const tagMethods = {
      dispatchEvent
    };
    const tagPrivateMethods = {};
    const updateVisible = () => {
      reactData.showTag = props.visible !== false;
    };
    const clickEvent = (evnt) => {
      const { loading } = props;
      if (!loading) {
        dispatchEvent("click", {}, evnt);
      }
    };
    const dblclickEvent = (evnt) => {
      const { loading } = props;
      if (!loading) {
        dispatchEvent("dblclick", {}, evnt);
      }
    };
    const closeEvent = (evnt) => {
      const { loading } = props;
      if (!loading) {
        const visible = !reactData.showTag;
        reactData.showTag = visible;
        emit("update:visible", visible);
        dispatchEvent("close", { visible }, evnt);
      }
    };
    Object.assign($xeTag, tagMethods, tagPrivateMethods);
    const renderContent = () => {
      const { icon: icon$1, content, closable, closeIcon, loading } = props;
      const defaultSlot = slots.default;
      const iconSlot = slots.icon;
      const closeIconSlot = slots.closeIcon || slots["close-icon"];
      return [
        iconSlot || icon$1 ? vue.h("span", {
          class: "vxe-tag--icon"
        }, iconSlot ? iconSlot({}) : [
          vue.h("i", {
            class: icon$1
          })
        ]) : index_esm.renderEmptyElement(),
        vue.h("span", {
          class: "vxe-tag--content"
        }, defaultSlot ? defaultSlot({}) : XEUtils.toValueString(content)),
        loading || closable ? vue.h("span", {
          class: loading ? "vxe-tag--loading" : "vxe-tag--close",
          onClick: closeEvent
        }, !loading && closeIconSlot ? closeIconSlot({}) : [
          vue.h("i", {
            class: loading ? icon.getIcon().TAG_LOADING : closeIcon || icon.getIcon().TAG_CLOSE
          })
        ]) : index_esm.renderEmptyElement()
      ];
    };
    const renderVN = () => {
      const { status, color, title, round, border, loading } = props;
      const { showTag } = reactData;
      const vSize = computeSize.value;
      if (!showTag) {
        return index_esm.renderEmptyElement();
      }
      return vue.h("span", {
        ref: refElem,
        class: ["vxe-tag", {
          [`size--${vSize}`]: vSize,
          [`theme--${status}`]: status && !color,
          [`color--${color}`]: color && !status,
          "is--round": round,
          "is--border": border,
          "is--loading": loading
        }],
        title,
        onClick: clickEvent,
        onDblclick: dblclickEvent
      }, renderContent());
    };
    vue.watch(() => props.visible, () => {
      updateVisible();
    });
    updateVisible();
    $xeTag.renderVN = renderVN;
    return $xeTag;
  },
  render() {
    return this.renderVN();
  }
});
exports.default = VxeTagComponent;
