'use strict';

const membership = require('./membership-14c44e7c.js');
const membershipConfig = require('./membership-config-6ba394cc.js');
const User = require('./User-286a0714.js');
const UserSettings = require('./UserSettings-016122e8.js');
const cookie = require('./cookie-c4d9848a.js');
const index = require('./index-33e96540.js');

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(groupId) {
  const { domain } = getRouteParams(location.pathname);
  const jwt = new cookie.CookieStorage().get('mt_at');
  const sessionToken = new cookie.CookieStorage().get('mt_st');
  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}`;
    headers['Session-Token'] = sessionToken;
  }
  else {
    headers['Session-Token'] = `NTdiMzY3NjBlNjNiY2UxZWViMDAwMDA0`;
  }
  context.groupId = groupId;
  return { context, headers };
}
function getUserSettings(timeFormat, timeZone, language, isZoomAuthenticated, weekStartDay = 'monday') {
  const authPlatforms = [];
  if (isZoomAuthenticated) {
    authPlatforms.push({
      id: 'zoom',
      name: 'Zoom',
      scope: []
    });
  }
  return UserSettings.UserSettings.decode({ timeFormat, timeZone, language, authPlatforms, weekStartDay });
}
function generateMembershipForRole(role) {
  return membership.Membership.decode({
    config: generateMembershipConfigForRole(role),
  });
}
function generateMembershipConfigForRole(role) {
  return membershipConfig.MembershipConfig.decode({
    _id: role === 'mentor' ? 'mentors' : 'mentees',
    roleName: role
  });
}
function getUser(id) {
  return User.User.decode({ _id: id });
}

exports.generateMembershipConfigForRole = generateMembershipConfigForRole;
exports.generateMembershipForRole = generateMembershipForRole;
exports.getRouteParams = getRouteParams;
exports.getSessionDetails = getSessionDetails;
exports.getUser = getUser;
exports.getUserSettings = getUserSettings;
