'use strict';

const kimlikApi = require('./kimlikApi-6a581864.js');
const cookie = require('./cookie-8a49bf23.js');

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

/**
 * Returns the session from the storage.
 */
const getSessionData = (storage = getCookieStorage()) => ({
  token: storage.get(kimlikApi.STORAGE_KEY_KIMLIK_TOKEN),
  uid: storage.get(kimlikApi.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,
    storage: getSessionData(storage),
  });
  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 });
  }
}

exports.getCookieStorage = getCookieStorage;
exports.getSessionData = getSessionData;
exports.isUserLoggedIn = isUserLoggedIn;
exports.logout = logout;
