"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const pageEnum = require("../enums/pageEnum.js");
const pathConst = require("../settings/pathConst.js");
require("../../node_modules/.pnpm/crypto-js@4.1.1/node_modules/crypto-js/index.js");
const storageEnum = require("../enums/storageEnum.js");
const storage = require("./storage.js");
const index = require("../router/index.js");
const routerTurnByName = (pageName, isReplace, windowOpen) => {
  if (windowOpen) {
    const path = fetchPathByName(pageName, "href");
    openNewWindow(path);
    return;
  }
  if (isReplace) {
    index.default.replace({
      name: pageName
    });
    return;
  }
  index.default.push({
    name: pageName
  });
};
const fetchPathByName = (pageName, p) => {
  try {
    const pathData = index.default.resolve({
      name: pageName
    });
    return p ? pathData[p] : pathData;
  } catch (error) {
    window["$message"].warning("查询路由信息失败，请联系管理员！");
  }
};
const routerTurnByPath = (path, query, isReplace, windowOpen) => {
  let fullPath = "";
  if (query == null ? void 0 : query.length) {
    fullPath = `${path}/${query.join("/")}`;
  }
  if (windowOpen) {
    return openNewWindow(fullPath);
  }
  if (isReplace) {
    index.default.replace({
      path: fullPath
    });
    return;
  }
  index.default.push({
    path: fullPath
  });
};
const redirectErrorPage = (code) => {
  if (!code)
    return false;
  const pageName = pageEnum.ErrorPageNameMap.get(code);
  if (!pageName)
    return false;
  routerTurnByName(pageName);
};
const reloadRoutePage = () => {
  routerTurnByName(pageEnum.PageEnum.RELOAD_NAME);
};
const logout = () => {
  storage.clearLocalStorage(storageEnum.StorageEnum.GO_LOGIN_INFO_STORE);
  routerTurnByName(pageEnum.PageEnum.BASE_LOGIN_NAME);
};
const openNewWindow = (url) => {
  return window.open(url, "_blank");
};
const openDoc = () => {
  openNewWindow(pathConst.docPath);
};
const openGiteeSourceCode = () => {
  openNewWindow(pathConst.giteeSourceCodePath);
};
const isPreview = () => {
  return document.location.hash.includes("preview");
};
const fetchRouteParamsLocation = () => {
  try {
    return document.location.hash.split("?")[0].split("/").pop() || "";
  } catch (error) {
    window["$message"].warning("查询路由信息失败，请联系管理员！");
    return "";
  }
};
exports.fetchPathByName = fetchPathByName;
exports.fetchRouteParamsLocation = fetchRouteParamsLocation;
exports.isPreview = isPreview;
exports.logout = logout;
exports.openDoc = openDoc;
exports.openGiteeSourceCode = openGiteeSourceCode;
exports.openNewWindow = openNewWindow;
exports.redirectErrorPage = redirectErrorPage;
exports.reloadRoutePage = reloadRoutePage;
exports.routerTurnByName = routerTurnByName;
exports.routerTurnByPath = routerTurnByPath;
