import { defineComponent, useModel, ref, h, openBlock, createElementBlock, createVNode, unref, isRef, withCtx, Fragment, renderList, createBlock, mergeProps, createElementVNode, createCommentVNode, toDisplayString, mergeModels } from 'vue';
import ContextMenu from '@imengyu/vue3-context-menu';
import { MeSvgIcon } from '../../svg-icon/index.mjs';
import { ElTabs, ElTabPane } from 'element-plus';

"use strict";
const _hoisted_1 = { class: "me-nav" };
const _hoisted_2 = ["onContextmenu"];
const __default__ = defineComponent({
  name: "me-nav"
});
var script = /* @__PURE__ */ defineComponent({
  ...__default__,
  props: /* @__PURE__ */ mergeModels({
    tabList: { type: Array, required: true, default: () => [] },
    menuHandle: { type: Function, required: false, default: () => null },
    tabProps: { type: Object, required: false, default: () => ({ key: "path", name: "path", label: "title" }) }
  }, {
    "modelValue": { type: [String, Number] },
    "modelModifiers": {}
  }),
  emits: /* @__PURE__ */ mergeModels(["changeTabEmit", "removeTabEmit"], ["update:modelValue"]),
  setup(__props, { emit: __emit }) {
    const props = __props;
    const emit = __emit;
    const model = useModel(__props, "modelValue");
    const activeTab = ref("");
    const modelTab = model.value ? model : activeTab.value;
    const onContextMenu = (e, item, currentIndex) => {
      e.preventDefault();
      const items = props.menuHandle(item, currentIndex) || [];
      if (!item.isHome) {
        items.splice(0, 0, {
          label: item.lock ? "\u89E3\u9501" : "\u9501\u5B9A",
          icon: h(MeSvgIcon, {
            name: item.lock ? "ri-lock-unlock-line" : "ri-lock-line"
          }),
          divided: true,
          onClick: () => {
            item.lock = !item.lock;
          }
        });
      }
      ContextMenu.showContextMenu({
        theme: "default",
        x: e.x,
        y: e.y,
        items
      });
    };
    const handleRemoveTab = (tabName) => {
      emit("removeTabEmit", tabName.toString());
    };
    const changeTab = (path) => {
      emit("changeTabEmit", path);
    };
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock("div", _hoisted_1, [
        createVNode(unref(ElTabs), {
          modelValue: unref(modelTab),
          "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => isRef(modelTab) ? modelTab.value = $event : null),
          type: "card",
          class: "me-tabs",
          onTabChange: changeTab,
          onTabRemove: handleRemoveTab
        }, {
          default: withCtx(() => [
            (openBlock(true), createElementBlock(
              Fragment,
              null,
              renderList(__props.tabList, (item, index) => {
                return openBlock(), createBlock(unref(ElTabPane), mergeProps({
                  key: item[__props.tabProps.key],
                  label: item[__props.tabProps.label],
                  name: item[__props.tabProps.name],
                  closable: !item.isHome && !item.lock,
                  style: { "vertical-align": "middle" }
                }, { ref_for: true }, _ctx.$attrs), {
                  label: withCtx(() => [
                    createElementVNode("div", {
                      class: "tabs-item-label",
                      onContextmenu: ($event) => onContextMenu($event, item, index)
                    }, [
                      item.icon ? (openBlock(), createBlock(unref(MeSvgIcon), {
                        key: 0,
                        style: { "margin-right": "3px" },
                        name: item.icon
                      }, null, 8, ["name"])) : createCommentVNode("v-if", true),
                      createElementVNode(
                        "span",
                        null,
                        toDisplayString(item.title),
                        1
                        /* TEXT */
                      ),
                      item.lock ? (openBlock(), createBlock(unref(MeSvgIcon), {
                        key: 1,
                        size: 12,
                        style: { "padding-left": "3px" },
                        name: "ri-lock-line"
                      })) : createCommentVNode("v-if", true)
                    ], 40, _hoisted_2)
                  ]),
                  _: 2
                  /* DYNAMIC */
                }, 1040, ["label", "name", "closable"]);
              }),
              128
              /* KEYED_FRAGMENT */
            ))
          ]),
          _: 1
          /* STABLE */
        }, 8, ["modelValue"])
      ]);
    };
  }
});

export { script as default };
//# sourceMappingURL=nav.vue2.mjs.map
