import Cookies from 'js-cookie';
import { ElMessage } from 'element-plus';
import { useLoginStore } from '../../../hooks/store/useLogin/index.mjs';
import { useGlobalConfig } from '../../../hooks/base/useGlobalConfig/index.mjs';

const res401Interceptors = async (service, config) => {
  const logingStore = useLoginStore();
  Cookies.remove("token", { domain: ".giikin.com" });
  Cookies.remove("token", { domain: ".giikin.cn" });
  Cookies.remove("token");
  const importMetaEnv = useGlobalConfig("env");
  if (importMetaEnv.value.DEV) {
    Cookies.remove("guard_token");
  }
  logingStore.userToken = void 0;
  logingStore.userId = void 0;
  logingStore.showLogin = true;
  ElMessage({
    message: "\u8BF7\u5728\u5F39\u6846\u4E2D\u91CD\u65B0\u767B\u5F55",
    type: "error",
    duration: 5 * 1e3,
    grouping: true,
    showClose: true
  });
  const res = await Promise.race([logingStore.onLoginResultPromise(), logingStore.onCloseLoginResultPromise()]);
  if (!res) {
    return Promise.reject({ code: 400, data: null, message: "\u767B\u5F55\u5F39\u7A97\u5DF2\u5173\u95ED" });
  }
  if (service && config) {
    return service(config);
  }
  return Promise.reject("\u672C\u6B21\u8BF7\u6C42\u7ED3\u675F");
};
const req401Interceptors = () => {
  const logingStore = useLoginStore();
  ElMessage({
    message: "\u8BF7\u5728\u5F39\u6846\u4E2D\u91CD\u65B0\u767B\u5F55",
    type: "error",
    duration: 5 * 1e3,
    grouping: true,
    showClose: true
  });
  return logingStore.showLogin = true;
};

export { req401Interceptors, res401Interceptors };
//# sourceMappingURL=interceptors.mjs.map
