"use strict";
const vue = require("vue");
const styleClass = require("../_utils/style-class.js");
const types = require("./types.js");
const icons = require("../_utils/icons.js");
const is = require("../_utils/is.js");
const _hoisted_1 = {
  key: 0,
  class: "o-tag-icon"
};
const _hoisted_2 = { class: "o-tag-label" };
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
  __name: "OTag",
  props: types.tagProps,
  emits: ["update:visible", "close"],
  setup(__props, { emit: __emit }) {
    const props = __props;
    const emits = __emit;
    const round = styleClass.getRoundClass(props, "tag");
    const isVisible = vue.ref(props.visible ?? props.defaultVisible);
    vue.watch(
      () => props.visible,
      (val) => {
        if (!is.isUndefined(val)) {
          isVisible.value = val;
        }
      }
    );
    const onClose = async (ev) => {
      ev.stopPropagation();
      if (is.isFunction(props.beforeClose)) {
        const rlt = await props.beforeClose();
        if (rlt) {
          isVisible.value = false;
          emits("update:visible", isVisible.value);
          emits("close", ev);
          return;
        }
      }
      isVisible.value = false;
      emits("update:visible", isVisible.value);
      emits("close", ev);
    };
    return (_ctx, _cache) => {
      return isVisible.value ? (vue.openBlock(), vue.createElementBlock(
        "span",
        {
          key: 0,
          class: vue.normalizeClass(["o-tag", [`o-tag-${props.variant}`, `o-tag-${props.color}`, `o-tag-${props.size}`, vue.unref(round).class.value]]),
          style: vue.normalizeStyle(vue.unref(round).style.value)
        },
        [
          _ctx.$slots.icon ? (vue.openBlock(), vue.createElementBlock("span", _hoisted_1, [
            vue.renderSlot(_ctx.$slots, "icon")
          ])) : vue.createCommentVNode("v-if", true),
          vue.createElementVNode("span", _hoisted_2, [
            vue.renderSlot(_ctx.$slots, "default")
          ]),
          props.closable ? (vue.openBlock(), vue.createElementBlock("span", {
            key: 1,
            class: "o-tag-close",
            onClick: onClose
          }, [
            vue.createVNode(vue.unref(icons.IconClose))
          ])) : vue.createCommentVNode("v-if", true)
        ],
        6
        /* CLASS, STYLE */
      )) : vue.createCommentVNode("v-if", true);
    };
  }
});
module.exports = _sfc_main;
