import { useAppStore } from "@/stores/app.js";
import Cache from "../utils/cache";
// import { Debounce } from "@/utils/validate.js";

import {
  USER_INFO,TOKEN,CITYINFO
} from "@/config/cache";

function prePage() {
  let pages = getCurrentPages();
  let prePage = pages[pages.length - 1];
  return prePage.route;
}

// export const toLogin = Debounce(_toLogin, 800);

export function toLogin(push, pathLogin) {
  const appStore = useAppStore();
  // appStore.LOGOUT();
  // let path = prePage();
  // let login_back_url = Cache.get(BACK_URL);


  uni.navigateTo({
    url: "/pages/login/login",
  });
}

export function checkLogin() {
  let userInfo = Cache.get(USER_INFO) ? JSON.parse(Cache.get(USER_INFO)) : null;
  let token = Cache.get(TOKEN);
  const appStore = useAppStore();
  if (userInfo && token) {
    return true;
  } else {
    Cache.clear(TOKEN);
    Cache.clear(USER_INFO);
    return false;
  }
}
