import { USER_INFO, USER_PROFILE, LOGIN_PROFILE, TOKEN_LOGIN, TOKEN } from "../constants/AppConstants";
import { KVStore } from "../utils/KVStore";
import { router } from "@kit.ArkUI";

/**
 * 注意：涉及Router的只有启动页（SplashScreenPage.ets）和登录页（LoginPage.ets），其他页面请使用Navigator进行跳转
 */

export function routerLogin(fromSource: string, isClear: boolean) {
  if (isClear) {
    KVStore.getInstance().put(USER_INFO, '');
    KVStore.getInstance().put(USER_PROFILE, '')
    KVStore.getInstance().put(LOGIN_PROFILE, '');         //持久化登录信息
    KVStore.getInstance().put(TOKEN_LOGIN, '');         //持久化token
    KVStore.getInstance().put(TOKEN, '');               //持久化token
  }

  //回到登录页（登录页将会清理router栈和NavPathStack栈）
  router.pushUrl({
    url: 'pages/LoginPage',
    params: {
      from: fromSource
    }
  })
}
export function routerIndex() {
  router.replaceUrl({ url: 'pages/Index' });
}

