import { defineComponent, reactive, computed, onMounted, onUnmounted, watch, resolveComponent, openBlock, createBlock, Transition, withCtx, withDirectives, createElementBlock, normalizeStyle, createElementVNode, Fragment, renderList, createVNode, toDisplayString, createCommentVNode, vShow } from 'vue';

const _hoisted_1 = ["aria-hidden"];
const _hoisted_2 = { class: "el-dropdown-menu" };
const _hoisted_3 = ["onClick"];
var _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "contextmenu",
  props: {
    dropdown: {
      type: Object,
      default: () => {
        return {
          x: 0,
          y: 0
        };
      }
    }
  },
  emits: ["currentContextmenuClick"],
  setup(__props, { expose: __expose, emit: __emit }) {
    const props = __props;
    const emit = __emit;
    const state = reactive({
      isShow: false,
      dropdownList: [
        { contextMenuClickId: 0, txt: "message.tagsView.refresh", affix: false, icon: "ele-RefreshRight" },
        { contextMenuClickId: 1, txt: "message.tagsView.close", affix: false, icon: "ele-Close" },
        { contextMenuClickId: 2, txt: "message.tagsView.closeOther", affix: false, icon: "ele-CircleClose" },
        { contextMenuClickId: 3, txt: "message.tagsView.closeAll", affix: false, icon: "ele-FolderDelete" },
        {
          contextMenuClickId: 4,
          txt: "message.tagsView.fullscreen",
          affix: false,
          icon: "iconfont icon-fullscreen"
        }
      ],
      item: {},
      arrowLeft: 10
    });
    const dropdowns = computed(() => {
      if (props.dropdown.x + 117 > document.documentElement.clientWidth) {
        return {
          x: document.documentElement.clientWidth - 117 - 5,
          y: props.dropdown.y
        };
      } else {
        return props.dropdown;
      }
    });
    const onCurrentContextmenuClick = (contextMenuClickId) => {
      emit("currentContextmenuClick", Object.assign({}, { contextMenuClickId }, state.item));
    };
    const openContextmenu = (item) => {
      var _a;
      state.item = item;
      ((_a = item.meta) == null ? void 0 : _a.isAffix) ? state.dropdownList[1].affix = true : state.dropdownList[1].affix = false;
      closeContextmenu();
      setTimeout(() => {
        state.isShow = true;
      }, 10);
    };
    const closeContextmenu = () => {
      state.isShow = false;
    };
    onMounted(() => {
      document.body.addEventListener("click", closeContextmenu);
    });
    onUnmounted(() => {
      document.body.removeEventListener("click", closeContextmenu);
    });
    watch(
      () => props.dropdown,
      ({ x }) => {
        if (x + 117 > document.documentElement.clientWidth) state.arrowLeft = 117 - (document.documentElement.clientWidth - x);
        else state.arrowLeft = 10;
      },
      {
        deep: true
      }
    );
    __expose({
      openContextmenu
    });
    return (_ctx, _cache) => {
      const _component_SvgIcon = resolveComponent("SvgIcon");
      return openBlock(), createBlock(Transition, {
        name: "el-collapse-transition",
        persisted: ""
      }, {
        default: withCtx(() => [
          withDirectives((openBlock(), createElementBlock("div", {
            "aria-hidden": state.isShow ? false : true,
            class: "el-dropdown__popper el-popper is-light is-pure custom-contextmenu",
            role: "tooltip",
            "data-popper-placement": "bottom",
            style: normalizeStyle(`top: ${dropdowns.value.y + 5}px;left: ${dropdowns.value.x}px;`),
            key: Math.random()
          }, [
            createElementVNode("ul", _hoisted_2, [
              (openBlock(true), createElementBlock(
                Fragment,
                null,
                renderList(state.dropdownList, (v, k) => {
                  return openBlock(), createElementBlock(
                    Fragment,
                    null,
                    [
                      !v.affix ? (openBlock(), createElementBlock("li", {
                        class: "el-dropdown-menu__item",
                        "aria-disabled": "false",
                        tabindex: "-1",
                        key: k,
                        onClick: ($event) => onCurrentContextmenuClick(v.contextMenuClickId)
                      }, [
                        createVNode(_component_SvgIcon, {
                          name: v.icon
                        }, null, 8, ["name"]),
                        createElementVNode(
                          "span",
                          null,
                          toDisplayString(_ctx.$t(v.txt)),
                          1
                          /* TEXT */
                        )
                      ], 8, _hoisted_3)) : createCommentVNode("v-if", true)
                    ],
                    64
                    /* STABLE_FRAGMENT */
                  );
                }),
                256
                /* UNKEYED_FRAGMENT */
              ))
            ]),
            createElementVNode(
              "div",
              {
                class: "el-popper__arrow",
                style: normalizeStyle({ left: `${state.arrowLeft}px` })
              },
              null,
              4
              /* STYLE */
            )
          ], 12, _hoisted_1)), [
            [vShow, state.isShow]
          ])
        ]),
        _: 1
        /* STABLE */
      });
    };
  }
});

export { _sfc_main as default };
