import { S as STORAGE_KEY_KIMLIK_TOKEN, a as STORAGE_KEY_KIMLIK_USER_ID } from './kimlik-api-66e341bd.js';
import { C as CookieStorage } from './cookie-9f22e0fb.js';

function getCookieStorage() {
  return new CookieStorage();
}

/**
 * Returns the session from the storage.
 */
const getSessionData = (storage = getCookieStorage()) => ({
  token: storage.get(STORAGE_KEY_KIMLIK_TOKEN),
  uid: storage.get(STORAGE_KEY_KIMLIK_USER_ID),
});
/**
 * Returns true if there is user data saved in the browser storage.
 */
function isUserLoggedIn(storage, logger) {
  const hasToken = !!getSessionData(storage).token;
  logger === null || logger === void 0 ? void 0 : logger.new('KimlikUtilFunctions').debugGroup('isUserLoggedIn', {
    result: hasToken,
    sessionData: getSessionData(storage),
    storage: storage.getAll(),
  });
  return hasToken;
}
/**
 * Sends the logout request and clears the storage.
 */
function logout(redirectTo = '/', kimlikApi, storage = getCookieStorage(), navigate = (config) => (window.location = config.path)) {
  if (kimlikApi) {
    kimlikApi === null || kimlikApi === void 0 ? void 0 : kimlikApi.logout().then(() => {
      storage.clear();
      navigate({ path: redirectTo });
    });
  }
  else {
    storage.clear();
    navigate({ path: redirectTo });
  }
}

export { getCookieStorage as a, getSessionData as g, isUserLoggedIn as i, logout as l };
