'use strict';

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

var vue = require('vue');
var ContextMenu = require('@imengyu/vue3-context-menu');
var index = require('../../svg-icon/index.js');
var elementPlus = require('element-plus');

"use strict";
const _hoisted_1 = { class: "me-nav" };
const _hoisted_2 = ["onContextmenu"];
const __default__ = vue.defineComponent({
  name: "me-nav"
});
var script = /* @__PURE__ */ vue.defineComponent({
  ...__default__,
  props: /* @__PURE__ */ vue.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__ */ vue.mergeModels(["changeTabEmit", "removeTabEmit"], ["update:modelValue"]),
  setup(__props, { emit: __emit }) {
    const props = __props;
    const emit = __emit;
    const model = vue.useModel(__props, "modelValue");
    const activeTab = vue.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: vue.h(index.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 vue.openBlock(), vue.createElementBlock("div", _hoisted_1, [
        vue.createVNode(vue.unref(elementPlus.ElTabs), {
          modelValue: vue.unref(modelTab),
          "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => vue.isRef(modelTab) ? modelTab.value = $event : null),
          type: "card",
          class: "me-tabs",
          onTabChange: changeTab,
          onTabRemove: handleRemoveTab
        }, {
          default: vue.withCtx(() => [
            (vue.openBlock(true), vue.createElementBlock(
              vue.Fragment,
              null,
              vue.renderList(__props.tabList, (item, index$1) => {
                return vue.openBlock(), vue.createBlock(vue.unref(elementPlus.ElTabPane), vue.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: vue.withCtx(() => [
                    vue.createElementVNode("div", {
                      class: "tabs-item-label",
                      onContextmenu: ($event) => onContextMenu($event, item, index$1)
                    }, [
                      item.icon ? (vue.openBlock(), vue.createBlock(vue.unref(index.MeSvgIcon), {
                        key: 0,
                        style: { "margin-right": "3px" },
                        name: item.icon
                      }, null, 8, ["name"])) : vue.createCommentVNode("v-if", true),
                      vue.createElementVNode(
                        "span",
                        null,
                        vue.toDisplayString(item.title),
                        1
                        /* TEXT */
                      ),
                      item.lock ? (vue.openBlock(), vue.createBlock(vue.unref(index.MeSvgIcon), {
                        key: 1,
                        size: 12,
                        style: { "padding-left": "3px" },
                        name: "ri-lock-line"
                      })) : vue.createCommentVNode("v-if", true)
                    ], 40, _hoisted_2)
                  ]),
                  _: 2
                  /* DYNAMIC */
                }, 1040, ["label", "name", "closable"]);
              }),
              128
              /* KEYED_FRAGMENT */
            ))
          ]),
          _: 1
          /* STABLE */
        }, 8, ["modelValue"])
      ]);
    };
  }
});

exports.default = script;
//# sourceMappingURL=nav.vue2.js.map
