'use strict';

const index = require('./index-13fb62eb.js');
const cookie = require('./cookie-8a49bf23.js');

const mentornityApiEndpoint = 'https://api.mentornity.com';
// export const mentornityApiEndpoint = 'http://localhost:1707';

const appRoute = '/:domain(/:page)(/:id)';
function getRouteParams(pathname) {
  // console.log(pathname, new Route(appRoute).match(pathname));
  return new index.routeParser(appRoute).match(pathname);
}

function getSessionDetails() {
  const { domain } = getRouteParams(location.pathname);
  const jwt = new cookie.CookieStorage().get('mt_at');
  const context = {
    organisationDomain: domain,
    organisationId: new cookie.CookieStorage().get('mt_oid'),
    userId: new cookie.CookieStorage().get('mt_uid'),
    role: new cookie.CookieStorage().get('mt_role'),
  };
  const headers = {
    Client: 'd2ViLWNsaWVu',
  };
  if (jwt) {
    headers['Authorization'] = `Bearer ${jwt}`;
  }
  else {
    headers['Session-Token'] = `NTdiMzY3NjBlNjNiY2UxZWViMDAwMDA0`;
  }
  return { context, headers };
}

exports.getRouteParams = getRouteParams;
exports.getSessionDetails = getSessionDetails;
exports.mentornityApiEndpoint = mentornityApiEndpoint;
