import Taro from "@tarojs/taro";

const PRESERVE_KEYS = new Set([
  "xlh_access_token",
  "xlh_token_expiry",
  "xlh_refresh_token"
]);

export function clearRuntimeCachePreserveLogin() {
  let removed = 0;
  try {
    const info = Taro.getStorageInfoSync();
    const keys = Array.isArray(info?.keys) ? info.keys : [];
    keys.forEach((key) => {
      if (PRESERVE_KEYS.has(key)) return;
      Taro.removeStorageSync(key);
      removed += 1;
    });
  } catch {
    // Fallback for environments where getStorageInfoSync is unavailable.
  }
  return removed;
}
