import { defineComponent, defineAsyncComponent, ref, reactive, computed, onMounted, resolveComponent, openBlock, createElementBlock, normalizeStyle, renderSlot, createVNode, withCtx, createElementVNode, createTextVNode, toDisplayString, unref, createBlock, normalizeClass, Fragment, renderList, createCommentVNode } from 'vue';
import { ElNotification, ElMessage, ElMessageBox } from 'element-plus';
import { Avatar, Loading, Lock, CircleCloseFilled } from '@element-plus/icons-vue';
import { useRouter } from 'vue-router';
import screenfull from 'screenfull';
import { useI18n } from 'vue-i18n';
import { storeToRefs } from 'pinia';
import '../../../../../stores/index.mjs';
import '../../../../../utils/index.mjs';
import '../../../../../api/index.mjs';
import { getCountryCode, languageList } from '../../../../../locale/index.mjs';
import '../../../../../hooks/index.mjs';
import emitter from '../../../../../utils/mitt.mjs';
import Push from 'push.js';
import { useRoutesList } from '../../../../../stores/routesList.mjs';
import { useUserInfo } from '../../../../../stores/userInfo.mjs';
import { useThemeConfig } from '../../../../../stores/themeConfig.mjs';
import { useFormEvents } from '../../../../../hooks/composables/useDialogEvents.mjs';
import { Local, Session } from '../../../../../utils/storage.mjs';
import { useBaseApi } from '../../../../../api/base/index.mjs';
import { signalR } from '../../../../../utils/signalR.mjs';
import { showFileUrl } from '../../../../../utils/uploadfileurl.mjs';
import { clearAccessTokens } from '../../../../../utils/request.mjs';

const _hoisted_1 = { class: "layout-navbars-breadcrumb-user-icon" };
const _hoisted_2 = ["title"];
const _hoisted_3 = { class: "layout-navbars-breadcrumb-user-icon" };
const _hoisted_4 = { class: "flex items-center" };
const _hoisted_5 = { class: "mr-2" };
const _hoisted_6 = { style: { "margin-left": "10px" } };
const _hoisted_7 = ["title"];
const _hoisted_8 = { class: "layout-navbars-breadcrumb-user-icon" };
const _hoisted_9 = ["title"];
const _hoisted_10 = { class: "layout-navbars-breadcrumb-user-link" };
const _hoisted_11 = ["src"];
var _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "user",
  setup(__props) {
    const UserNews = defineAsyncComponent(() => import('./userNews.vue.mjs'));
    const UpgradeInfo = defineAsyncComponent(() => import('./upgradeInfo.vue.mjs'));
    const routeStores = useRoutesList();
    const { locale, t } = useI18n();
    const router = useRouter();
    const stores = useUserInfo();
    const storesThemeConfig = useThemeConfig();
    const { userInfos } = storeToRefs(stores);
    const { themeConfig } = storeToRefs(storesThemeConfig);
    const upgradeInfoRef = ref();
    const currentCountryCode = ref(getCountryCode(themeConfig.value.globalI18n));
    const state = reactive({
      isScreenfull: false,
      disabledI18n: "zh-cn",
      disabledSize: "large",
      noticeList: [],
      // 站内信列表
      tagsRefsIndex: 0,
      tagsViewList: [],
      tagsViewRoutesList: []
    });
    const events = useFormEvents();
    const layoutUserFlexNum = computed(() => {
      let num = "";
      const { layout, isClassicSplitMenu } = themeConfig.value;
      const layoutArr = ["defaults", "columns"];
      if (layoutArr.includes(layout) || layout === "classic" && !isClassicSplitMenu) num = "1";
      else num = "";
      return num;
    });
    const hasUnreadNotice = computed(() => {
      return state.noticeList.some((r) => r.readStatus == void 0 || r.readStatus == 0);
    });
    const onScreenfullClick = () => {
      if (!screenfull.isEnabled) {
        ElMessage.warning("\u6682\u4E0D\u4E0D\u652F\u6301\u5168\u5C4F");
        return false;
      }
      screenfull.toggle();
      screenfull.on("change", () => {
        if (screenfull.isFullscreen) state.isScreenfull = true;
        else state.isScreenfull = false;
      });
    };
    const onLayoutSetingClick = () => {
      emitter.emit("openSettingsDrawer");
    };
    const onHandleCommandClick = (path) => {
      if (path === "clearCache") {
        Session.clear();
        Local.clear();
        window.location.reload();
      } else if (path === "lockScreen") {
        Local.remove("themeConfig");
        themeConfig.value.isLockScreen = true;
        themeConfig.value.lockScreenTime = 1;
        Local.set("themeConfig", themeConfig.value);
      } else if (path === "logOut") {
        ElMessageBox({
          closeOnClickModal: false,
          closeOnPressEscape: false,
          title: t("message.user.logOutTitle"),
          message: t("message.user.logOutMessage"),
          type: "warning",
          showCancelButton: true,
          confirmButtonText: t("message.user.logOutConfirm"),
          cancelButtonText: t("message.user.logOutCancel"),
          // buttonSize: 'default',
          beforeClose: async (action, instance, done) => {
            if (action === "confirm") {
              instance.confirmButtonLoading = true;
              instance.confirmButtonText = t("message.user.logOutExit");
              try {
                await useBaseApi("sysAuth").post(null, "logout");
              } catch (error) {
                console.error(error);
              }
              instance.confirmButtonLoading = false;
              done();
            } else {
              done();
            }
          }
        }).then(async () => {
          await signalR.stop();
          clearAccessTokens();
        }).catch(() => {
        });
      } else {
        router.push(path);
      }
    };
    const onSearchClick = () => {
      events.onFormDialogOpen({
        name: "searchFormMenu"
      });
    };
    const onOnlineUserClick = () => {
      events.onFormDialogOpen({
        name: "onlineUsers"
      });
    };
    const onComponentSizeChange = (size) => {
      Local.remove("themeConfig");
      themeConfig.value.globalComponentSize = size;
      Local.set("themeConfig", themeConfig.value);
      initI18nOrSize("globalComponentSize", "disabledSize");
    };
    const onLanguageChange = async (lang) => {
      Local.remove("themeConfig");
      themeConfig.value.globalI18n = lang;
      Local.set("themeConfig", themeConfig.value);
      currentCountryCode.value = getCountryCode(lang);
      locale.value = lang;
      events.onFormDialogOpen({
        name: "setFBrowserTitle"
      });
      initI18nOrSize("globalI18n", "disabledI18n");
      refreshCurrentTabpage();
      await useBaseApi("sysCommon").post(null, "setCulture/?culture=" + lang);
    };
    const onChatClick = () => {
      router.push({
        path: "/llm/aiChat"
      });
    };
    const refreshCurrentTabpage = () => {
      emitter.emit("onCurrentContextmenuClick", { ...routeStores.currentRoute, contextMenuClickId: 0 });
    };
    const initI18nOrSize = (value, attr) => {
      state[attr] = Local.get("themeConfig")[value];
    };
    onMounted(async () => {
      var _a, _b;
      if (Local.get("themeConfig")) {
        initI18nOrSize("globalComponentSize", "disabledSize");
        initI18nOrSize("globalI18n", "disabledI18n");
      }
      if (Push.Permission.GRANTED) {
        Push.Permission.request(void 0, void 0);
      }
      document.addEventListener("visibilitychange", () => {
        if (!document.hidden) {
          Push.clear();
        }
      });
      var res = await useBaseApi("sysNotice").get(null, "unReadList");
      state.noticeList = (_a = res.data.result) != null ? _a : [];
      signalR.on("PublicNotice", receiveNotice);
      var res1 = await useBaseApi("sysUpgrade").get(null, "lastUnRead");
      if (res1.data.result != null) {
        (_b = upgradeInfoRef.value) == null ? void 0 : _b.openDialog(res1.data.result);
      }
      await changePassword();
    });
    const receiveNotice = (msg) => {
      state.noticeList.unshift(msg);
      ElNotification({
        title: "\u63D0\u793A",
        message: "\u60A8\u6709\u4E00\u6761\u65B0\u6D88\u606F...",
        type: "info",
        position: "bottom-right"
      });
      Push.create("\u63D0\u793A", {
        body: "\u4F60\u6709\u4E00\u6761\u65B0\u7684\u6D88\u606F",
        icon: "logo.png",
        // public目录下的
        timeout: 4500
        // 通知显示时间，单位为毫秒
      });
    };
    const changePassword = async () => {
      var _a, _b;
      if (userInfos.value.accountType == 999) return;
      if (themeConfig.value.forceChangePassword == void 0) {
        while (themeConfig.value.forceChangePassword != void 0) {
          await new Promise((resolve) => setTimeout(resolve, 100));
        }
      }
      const enabledForceChangePassword = (_a = themeConfig.value.forceChangePassword) != null ? _a : false;
      if (enabledForceChangePassword && !userInfos.value.lastChangePasswordTime) {
        events.onFormDialogOpen({
          name: "changePassword"
        });
        return;
      }
      const passwordExpirationTime = (_b = themeConfig.value.passwordExpirationTime) != null ? _b : 0;
      if (passwordExpirationTime > 0) {
        const res = await useBaseApi("sysUser").post(null, "verifyPwdExpirationTime");
        if (!res.data.result) {
          events.onFormDialogOpen({
            name: "changePassword"
          });
        }
      }
    };
    return (_ctx, _cache) => {
      const _component_el_dropdown_item = resolveComponent("el-dropdown-item");
      const _component_el_dropdown_menu = resolveComponent("el-dropdown-menu");
      const _component_el_dropdown = resolveComponent("el-dropdown");
      const _component_ele_ChatDotRound = resolveComponent("ele-ChatDotRound");
      const _component_el_icon = resolveComponent("el-icon");
      const _component_ele_Search = resolveComponent("ele-Search");
      const _component_ele_Bell = resolveComponent("ele-Bell");
      const _component_el_badge = resolveComponent("el-badge");
      const _component_el_popover = resolveComponent("el-popover");
      const _component_ele_User = resolveComponent("ele-User");
      const _component_el_tooltip = resolveComponent("el-tooltip");
      const _component_ele_ArrowDown = resolveComponent("ele-ArrowDown");
      return openBlock(), createElementBlock(
        "div",
        {
          class: "layout-navbars-breadcrumb-user pr15",
          style: normalizeStyle({ flex: layoutUserFlexNum.value })
        },
        [
          renderSlot(_ctx.$slots, "user-before"),
          createVNode(_component_el_dropdown, {
            "show-timeout": 70,
            "hide-timeout": 50,
            trigger: "click",
            onCommand: onComponentSizeChange
          }, {
            dropdown: withCtx(() => [
              createVNode(_component_el_dropdown_menu, null, {
                default: withCtx(() => [
                  createVNode(_component_el_dropdown_item, {
                    command: "large",
                    disabled: state.disabledSize === "large"
                  }, {
                    default: withCtx(() => [
                      createTextVNode(
                        toDisplayString(_ctx.$t("message.user.dropdownLarge")),
                        1
                        /* TEXT */
                      )
                    ]),
                    _: 1
                    /* STABLE */
                  }, 8, ["disabled"]),
                  createVNode(_component_el_dropdown_item, {
                    command: "default",
                    disabled: state.disabledSize === "default"
                  }, {
                    default: withCtx(() => [
                      createTextVNode(
                        toDisplayString(_ctx.$t("message.user.dropdownDefault")),
                        1
                        /* TEXT */
                      )
                    ]),
                    _: 1
                    /* STABLE */
                  }, 8, ["disabled"]),
                  createVNode(_component_el_dropdown_item, {
                    command: "small",
                    disabled: state.disabledSize === "small"
                  }, {
                    default: withCtx(() => [
                      createTextVNode(
                        toDisplayString(_ctx.$t("message.user.dropdownSmall")),
                        1
                        /* TEXT */
                      )
                    ]),
                    _: 1
                    /* STABLE */
                  }, 8, ["disabled"])
                ]),
                _: 1
                /* STABLE */
              })
            ]),
            default: withCtx(() => [
              createElementVNode("div", _hoisted_1, [
                createElementVNode("i", {
                  class: "iconfont icon-ziti",
                  title: _ctx.$t("message.user.title0")
                }, null, 8, _hoisted_2)
              ])
            ]),
            _: 1
            /* STABLE */
          }),
          unref(themeConfig).i18NSwitch ? (openBlock(), createBlock(_component_el_dropdown, {
            key: 0,
            "show-timeout": 70,
            "hide-timeout": 50,
            trigger: "click",
            onCommand: onLanguageChange
          }, {
            dropdown: withCtx(() => [
              createVNode(_component_el_dropdown_menu, null, {
                default: withCtx(() => [
                  (openBlock(true), createElementBlock(
                    Fragment,
                    null,
                    renderList(unref(languageList), (value, key) => {
                      return openBlock(), createBlock(_component_el_dropdown_item, {
                        key,
                        command: key,
                        disabled: state.disabledI18n === key
                      }, {
                        default: withCtx(() => [
                          createElementVNode("div", _hoisted_4, [
                            createElementVNode("div", _hoisted_5, [
                              createElementVNode(
                                "span",
                                {
                                  class: normalizeClass(`fi fi-${unref(getCountryCode)(key)}`)
                                },
                                null,
                                2
                                /* CLASS */
                              )
                            ]),
                            createElementVNode(
                              "div",
                              _hoisted_6,
                              toDisplayString(value),
                              1
                              /* TEXT */
                            )
                          ])
                        ]),
                        _: 2
                        /* DYNAMIC */
                      }, 1032, ["command", "disabled"]);
                    }),
                    128
                    /* KEYED_FRAGMENT */
                  ))
                ]),
                _: 1
                /* STABLE */
              })
            ]),
            default: withCtx(() => [
              createElementVNode("div", _hoisted_3, [
                createElementVNode(
                  "span",
                  {
                    class: normalizeClass(`fi fi-${currentCountryCode.value}`)
                  },
                  null,
                  2
                  /* CLASS */
                )
              ])
            ]),
            _: 1
            /* STABLE */
          })) : createCommentVNode("v-if", true),
          createElementVNode("div", {
            class: "layout-navbars-breadcrumb-user-icon",
            onClick: onChatClick
          }, [
            createVNode(_component_el_icon, {
              title: _ctx.$t("message.user.chat")
            }, {
              default: withCtx(() => [
                createVNode(_component_ele_ChatDotRound)
              ]),
              _: 1
              /* STABLE */
            }, 8, ["title"])
          ]),
          createElementVNode("div", {
            class: "layout-navbars-breadcrumb-user-icon",
            onClick: onSearchClick
          }, [
            createVNode(_component_el_icon, {
              title: _ctx.$t("message.user.title2")
            }, {
              default: withCtx(() => [
                createVNode(_component_ele_Search)
              ]),
              _: 1
              /* STABLE */
            }, 8, ["title"])
          ]),
          createElementVNode("div", {
            class: "layout-navbars-breadcrumb-user-icon",
            onClick: onLayoutSetingClick
          }, [
            createElementVNode("i", {
              class: "icon-skin iconfont",
              title: _ctx.$t("message.user.title3")
            }, null, 8, _hoisted_7)
          ]),
          createElementVNode("div", _hoisted_8, [
            createVNode(_component_el_popover, {
              placement: "bottom",
              trigger: "hover",
              transition: "el-zoom-in-top",
              width: 400,
              persistent: false
            }, {
              reference: withCtx(() => [
                createVNode(_component_el_badge, { "is-dot": hasUnreadNotice.value }, {
                  default: withCtx(() => [
                    createVNode(_component_el_icon, {
                      title: _ctx.$t("message.user.title4")
                    }, {
                      default: withCtx(() => [
                        createVNode(_component_ele_Bell)
                      ]),
                      _: 1
                      /* STABLE */
                    }, 8, ["title"])
                  ]),
                  _: 1
                  /* STABLE */
                }, 8, ["is-dot"])
              ]),
              default: withCtx(() => [
                createVNode(unref(UserNews), {
                  noticeList: state.noticeList
                }, null, 8, ["noticeList"])
              ]),
              _: 1
              /* STABLE */
            })
          ]),
          createElementVNode("div", {
            class: "layout-navbars-breadcrumb-user-icon",
            onClick: onScreenfullClick
          }, [
            createElementVNode("i", {
              class: normalizeClass(["iconfont", !state.isScreenfull ? "icon-fullscreen" : "icon-tuichuquanping"]),
              title: state.isScreenfull ? _ctx.$t("message.user.title6") : _ctx.$t("message.user.title5")
            }, null, 10, _hoisted_9)
          ]),
          createElementVNode("div", {
            class: "layout-navbars-breadcrumb-user-icon mr10",
            onClick: onOnlineUserClick
          }, [
            createVNode(_component_el_icon, {
              title: _ctx.$t("message.list.onlineUser")
            }, {
              default: withCtx(() => [
                createVNode(_component_ele_User)
              ]),
              _: 1
              /* STABLE */
            }, 8, ["title"])
          ]),
          _ctx.$slots["user-dropdown"] ? renderSlot(_ctx.$slots, "user-dropdown", { key: 1 }, () => [
            renderSlot(_ctx.$slots, "user-dropdown")
          ]) : (openBlock(), createBlock(_component_el_dropdown, {
            key: 2,
            "show-timeout": 70,
            "hide-timeout": 50,
            size: "large",
            onCommand: onHandleCommandClick
          }, {
            dropdown: withCtx(() => [
              createVNode(_component_el_dropdown_menu, null, {
                default: withCtx(() => [
                  createCommentVNode(` <el-dropdown-item command="/dashboard/home">{{ $t('message.user.dropdown1') }}</el-dropdown-item> `),
                  createVNode(_component_el_dropdown_item, {
                    icon: unref(Avatar),
                    command: "/system/userCenter"
                  }, {
                    default: withCtx(() => [
                      createTextVNode(
                        toDisplayString(_ctx.$t("message.user.dropdown2")),
                        1
                        /* TEXT */
                      )
                    ]),
                    _: 1
                    /* STABLE */
                  }, 8, ["icon"]),
                  createVNode(_component_el_dropdown_item, {
                    icon: unref(Loading),
                    command: "clearCache"
                  }, {
                    default: withCtx(() => [
                      createTextVNode(
                        toDisplayString(_ctx.$t("message.user.dropdown3")),
                        1
                        /* TEXT */
                      )
                    ]),
                    _: 1
                    /* STABLE */
                  }, 8, ["icon"]),
                  createVNode(_component_el_dropdown_item, {
                    icon: unref(Lock),
                    divided: "",
                    command: "lockScreen"
                  }, {
                    default: withCtx(() => [
                      createTextVNode(
                        toDisplayString(_ctx.$t("message.layout.threeIsLockScreen")),
                        1
                        /* TEXT */
                      )
                    ]),
                    _: 1
                    /* STABLE */
                  }, 8, ["icon"]),
                  createVNode(_component_el_dropdown_item, {
                    icon: unref(CircleCloseFilled),
                    divided: "",
                    command: "logOut"
                  }, {
                    default: withCtx(() => [
                      createTextVNode(
                        toDisplayString(_ctx.$t("message.user.dropdown5")),
                        1
                        /* TEXT */
                      )
                    ]),
                    _: 1
                    /* STABLE */
                  }, 8, ["icon"])
                ]),
                _: 1
                /* STABLE */
              })
            ]),
            default: withCtx(() => [
              createElementVNode("span", _hoisted_10, [
                createVNode(_component_el_tooltip, {
                  effect: "dark",
                  placement: "left"
                }, {
                  content: withCtx(() => [
                    createTextVNode(
                      toDisplayString(_ctx.$t("message.list.account")) + "\uFF1A" + toDisplayString(unref(userInfos).account),
                      1
                      /* TEXT */
                    ),
                    _cache[0] || (_cache[0] = createElementVNode(
                      "br",
                      null,
                      null,
                      -1
                      /* CACHED */
                    )),
                    createTextVNode(
                      " " + toDisplayString(_ctx.$t("message.list.realName")) + "\uFF1A" + toDisplayString(unref(userInfos).realName),
                      1
                      /* TEXT */
                    ),
                    _cache[1] || (_cache[1] = createElementVNode(
                      "br",
                      null,
                      null,
                      -1
                      /* CACHED */
                    )),
                    createTextVNode(
                      " " + toDisplayString(_ctx.$t("message.list.phone")) + "\uFF1A" + toDisplayString(unref(userInfos).phone),
                      1
                      /* TEXT */
                    ),
                    _cache[2] || (_cache[2] = createElementVNode(
                      "br",
                      null,
                      null,
                      -1
                      /* CACHED */
                    )),
                    createTextVNode(
                      " " + toDisplayString(_ctx.$t("message.list.email")) + "\uFF1A" + toDisplayString(unref(userInfos).email),
                      1
                      /* TEXT */
                    ),
                    _cache[3] || (_cache[3] = createElementVNode(
                      "br",
                      null,
                      null,
                      -1
                      /* CACHED */
                    )),
                    createTextVNode(
                      " " + toDisplayString(_ctx.$t("message.list.orgName")) + "\uFF1A" + toDisplayString(unref(userInfos).orgName),
                      1
                      /* TEXT */
                    ),
                    _cache[4] || (_cache[4] = createElementVNode(
                      "br",
                      null,
                      null,
                      -1
                      /* CACHED */
                    )),
                    createTextVNode(
                      " " + toDisplayString(_ctx.$t("message.list.positionText")) + "\uFF1A" + toDisplayString(unref(userInfos).posName),
                      1
                      /* TEXT */
                    ),
                    _cache[5] || (_cache[5] = createElementVNode(
                      "br",
                      null,
                      null,
                      -1
                      /* CACHED */
                    ))
                  ]),
                  default: withCtx(() => [
                    createElementVNode("img", {
                      src: unref(showFileUrl)(unref(userInfos).avatar),
                      class: "layout-navbars-breadcrumb-user-link-photo mr5"
                    }, null, 8, _hoisted_11)
                  ]),
                  _: 1
                  /* STABLE */
                }),
                createTextVNode(
                  " " + toDisplayString(unref(userInfos).realName == "" ? unref(userInfos).account : unref(userInfos).realName) + " ",
                  1
                  /* TEXT */
                ),
                createVNode(_component_el_icon, { class: "el-icon--right" }, {
                  default: withCtx(() => [
                    createVNode(_component_ele_ArrowDown)
                  ]),
                  _: 1
                  /* STABLE */
                })
              ])
            ]),
            _: 1
            /* STABLE */
          })),
          createCommentVNode(' <Search ref="searchRef" /> '),
          createCommentVNode(' <OnlineUser ref="onlineUserRef" /> '),
          createCommentVNode(' <ChangePassword ref="changePasswordRef" /> '),
          createVNode(
            unref(UpgradeInfo),
            {
              ref_key: "upgradeInfoRef",
              ref: upgradeInfoRef
            },
            null,
            512
            /* NEED_PATCH */
          ),
          renderSlot(_ctx.$slots, "user-after")
        ],
        4
        /* STYLE */
      );
    };
  }
});

export { _sfc_main as default };
