'use strict';

const membership = require('./membership-310dd68e.js');
const User = require('./User-e15e0b6d.js');
const UserSettings = require('./UserSettings-fc04eb54.js');
const cookie = require('./cookie-ea977378.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, dateFormat, timeZone, language, isZoomAuthenticated, weekStartDay = 'monday') {
  const authPlatforms = [];
  if (isZoomAuthenticated) {
    authPlatforms.push({
      id: 'zoom',
      name: 'Zoom',
      scope: []
    });
  }
  return UserSettings.UserSettings.decode({ timeFormat, dateFormat, timeZone, language, authPlatforms, weekStartDay });
}
function generateMembershipForRole(role) {
  return membership.Membership.decode({
    config: generateMembershipConfigForRole(role),
  });
}
function generateMembershipConfigForRole(role) {
  return membership.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;
