'use strict';

const kimlikApi = require('./kimlikApi-85c6d3ac.js');
const utils = require('./utils-d768590e.js');
const User = require('./User-286a0714.js');
const index = require('./index-2efe9739.js');
const membership = require('./membership-dfbf512e.js');
const dataApi$1 = require('./dataApi-4fa79a50.js');
const appConfig = require('./app-config-e62f5843.js');
const membershipConfig = require('./membership-config-707b2c51.js');
const spaces = require('./spaces-2fa9fa10.js');
const index$4 = require('./index-74a00556.js');
const date = require('./date-25b104f6.js');
const tableListViewConfig = require('./table-list-view-config-298c7662.js');
const detailViewConfig = require('./detail-view-config-594cc3b7.js');
const filter = require('./filter-d5040f65.js');
const viewConfig$h = require('./view-config-ec5f62df.js');
const models = require('./models-19fd9c92.js');
const dataTransferField = require('./data-transfer-field-0ce05c1a.js');
const index$1 = require('./index-a8f1783c.js');
const InterceptorHandler = require('./InterceptorHandler-09a1e84b.js');
const formViewConfig = require('./form-view-config-51279874.js');
const ValidatorLength = require('./ValidatorLength-06e5c6f8.js');
const actions = require('./actions-d7eabd95.js');
const instance = require('./instance-79d61640.js');
const index$2 = require('./index-fe19a98b.js');
require('./index-ae305bae.js');
require('./data-model-c51de090.js');
const listFetchState = require('./list-fetch-state-7befe791.js');
const index$3 = require('./index-0cd3bcc0.js');
require('./index-d90390f1.js');
const nested = require('./nested-8980065f.js');
const timeZones = require('./time-zones-5b212929.js');
const attachment = require('./attachment-3090e25e.js');

class KimlikApiMentornity {
  constructor(endpoint, headers) {
    this.api = new kimlikApi.APIBase(endpoint, headers);
  }
  activateUser(_email, _firstName, _lastName, _password) {
    return Promise.reject(utils.notImplemented('KimlikApiMentornity.activateUser'));
  }
  addAuthInterceptor(token) {
    console.log('addAuthInterceptor', token);
  }
  login(email, password) {
    return new Promise(async (resolve) => {
      const response = await this.api.post('login', { email, password });
      resolve({ userId: response.user._id, jwt: response.accessToken });
    });
  }
  logout() {
    return Promise.resolve({});
  }
  register(_email, _firstName, _lastName, _password) {
    return Promise.reject(utils.notImplemented('KimlikApiMentornity.register'));
  }
  getSession() {
    return new Promise(async (resolve) => {
      const user = await this.api.get(`users/${index.getSessionData().uid}`);
      resolve({ user: User.User.decode(user) });
    });
  }
}

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

const membershipConfigs = {
  // mentees table
  'system-admins': membershipConfig.MembershipConfig.decode({
    _id: 'system-admins',
    _created: new Date(),
    _updated: new Date(),
    agreements: [],
    base: 'mentornity',
    fields: [
      {
        type: 'reference',
        id: 'user',
        otherCollection: 'users',
        isSingle: true,
        fields: [
          {
            type: 'text',
            id: 'firstName'
          },
          {
            type: 'text',
            id: 'lastName'
          },
        ]
      },
    ],
    name: 'system-admins',
    roleName: 'System Admin',
    space: spaces.spaces['mentornity'],
  }),
};

const ID$n = 'detail-view-error-log';
const viewConfig$g = detailViewConfig.DetailViewConfig.decode({
  _id: ID$n,
  base: 'mentornity',
  space: spaces.spaces['mentornity'],
  table: tableListViewConfig.dataConfigs['errorlogs'],
  title: 'Error Log',
  ui: {
    cardConfig: {
      body: {
        fields: [
          {
            fieldId: 'createdAt',
            fieldDisplay: new date.DateField('createdAt', 'Date').setDateFormat('DD.MM.YYYY HH:mm').setDataType(date.DateDataType.Unix),
          },
          {
            fieldId: 'user',
            fieldDisplay: new tableListViewConfig.RawDataField('user._id', 'User ID'),
          },
          {
            fieldId: 'session',
            fieldDisplay: new tableListViewConfig.RawDataField('session._id', 'Session ID'),
          },
          {
            fieldId: 'res',
          },
          {
            fieldId: 'status',
          },
          {
            fieldId: 'message',
          },
        ]
      },
    }
  },
  query: {
    filter: {
      comparison: filter.Comparison.Eq,
      id: '_id',
      value: '$id',
    },
  },
  type: viewConfig$h.AppViewType.DetailViewCard,
  params: {
    id: {
      required: true,
    },
  },
});

class ModifierRegexCharRemover extends InterceptorHandler.InterceptorConfig {
  constructor(regex) {
    super('modifierNonAlphanumericCharRemover');
    this.regex = regex;
  }
}
ModifierRegexCharRemover.id = 'modifierNonAlphanumericCharRemover';
class ModifierRegexCharRemoverHandler extends InterceptorHandler.InterceptorHandler {
  constructor(config) {
    super();
    this.config = config;
  }
  run(_context, _values, _field, value) {
    if (typeof value === 'string' || value instanceof String) {
      return {
        value: value.replace(new RegExp(this.config.regex, "gm"), ''),
      };
    }
    return { value };
  }
}
InterceptorHandler.registerInterceptor(ModifierRegexCharRemover.id, (config) => new ModifierRegexCharRemoverHandler(config));

class ChangeOrganisationDomainFormHandler {
  constructor() {
    const { jwt, sessionId } = index.getCookieStorage().getAll();
    this.api = instance.createMentornityApiInstance(mentornityApiEndpoint, {
      'Authorization': `Bearer ${jwt}`,
      'Client': 'd2ViLWFkbWlu',
      'Session-Token': sessionId,
    });
  }
  onSubmit(event) {
    const { values: { domain, organisationId } } = event.detail;
    return new Promise((resolve, reject) => {
      this.api.changeOrganisationDomain({ domain, organisationId }).then(() => {
        resolve({
          events: [
            new actions.InvalidationAction(ID$m, ID$l),
            new actions.InvalidationAction(ID$m, ID$5),
          ],
          navigation: {
            type: 'navigation',
            direction: 'back'
          }
        });
      }).catch(error => {
        if (error.data && error.data.message === 'domain-already-exists') {
          reject(['Domain is already used by another program.']);
          return;
        }
        reject(['Unexpected error']);
      });
    });
  }
}

const ID$m = 'form-view-organisation-change-domain';
const viewConfig$f = formViewConfig.FormViewConfig.decode({
  _id: ID$m,
  base: 'mentornity',
  title: 'Change Organisation Domain',
  space: spaces.spaces['mentornity'],
  table: tableListViewConfig.dataConfigs['organisations'],
  type: viewConfig$h.AppViewType.FormView,
  handler: new ChangeOrganisationDomainFormHandler(),
  ui: {
    fields: [
      // this field is passed by the parameters. this is a data holder field to pass the data to form handler
      {
        field: new dataTransferField.DataTransferField('organisationId'),
      },
      {
        field: new index$1.TextField('domain', 'New domain').addInterceptor('onBlur', new ModifierRegexCharRemover(' '))
          .addInterceptor('onSubmit', new tableListViewConfig.ValidatorRegex('[a-z0-9\-]'))
          .addInterceptor('onSubmit', new ValidatorLength.ValidatorLength(2, 100))
          .addInterceptor('onSubmit', new formViewConfig.ModifierTrimmer())
          .require(),
      },
    ],
  },
  params: {
    organisationId: {
      required: true,
    },
    domain: {
      required: true,
    },
  },
});

const ID$l = 'detail-view-organisation';
const viewConfig$e = detailViewConfig.DetailViewConfig.decode({
  _id: ID$l,
  base: 'mentornity',
  space: spaces.spaces['mentornity'],
  table: tableListViewConfig.dataConfigs['organisations'],
  title: 'Organisation',
  ui: {
    cardConfig: {
      header: {
        actions: [{
            ui: {
              name: 'change-domain',
              buttonType: 'button',
              label: 'Change Domain',
              scale: 'medium',
              view: 'solid'
            },
            data: {
              type: 'navigation',
              viewId: ID$m,
              direction: 'forward',
              placement: appConfig.ViewPlacement.Dialog,
              params: {
                conversionConfig: {
                  'item._id': 'organisationId',
                  'item.domain': 'domain',
                }
              }
            }
          }],
        cover: {
          fieldId: 'coverUrl',
          size: 256,
        },
        image: {
          fieldId: 'logoUrl',
          shape: 'rounded',
          size: 96,
          position: models.ImagePosition.Center,
        },
        title: {
          fieldId: 'title',
        },
      },
      body: {
        fields: [
          {
            fieldId: 'domain',
          },
          {
            fieldId: 'status',
          },
          {
            fieldId: 'model',
          },
          {
            fieldId: 'description',
            lines: 0,
          },
          {
            fieldId: 'createdAt',
          },
          {
            fieldId: 'webSiteUrl',
          },
          {
            fieldId: 'facebookUrl',
          },
          {
            fieldId: 'twitterUrl',
          },
          {
            fieldId: 'linkedInUrl',
          },
          {
            fieldId: '_id',
          },
        ]
      },
    }
  },
  type: viewConfig$h.AppViewType.DetailViewCard,
  params: {
    itemId: {
      required: true,
    },
  },
});

const ID$k = 'detail-view-form-response';
const viewConfig$d = detailViewConfig.DetailViewConfig.decode({
  _id: ID$k,
  base: 'mentornity',
  space: spaces.spaces['mentornity'],
  table: tableListViewConfig.dataConfigs['formResponses'],
  title: 'Form Response',
  ui: {
    cardConfig: {
      body: {
        fields: [
          {
            fieldId: 'createdAt',
          },
          {
            fieldDisplay: new index$1.TextField('data.phone', 'Phone'),
          },
          {
            fieldDisplay: new index$1.TextField('data.email', 'Email'),
          },
          {
            fieldDisplay: new index$1.TextField('data.name', 'Name'),
          },
          {
            fieldDisplay: new index$1.TextField('data.message', 'Message'),
            lines: 0,
          },
        ]
      },
    }
  },
  type: viewConfig$h.AppViewType.DetailViewCard,
  params: {
    itemId: {
      required: true,
    },
  },
});

const ID$j = 'detail-view-user-auth';
const viewConfig$c = detailViewConfig.DetailViewConfig.decode({
  _id: ID$j,
  base: 'mentornity',
  space: spaces.spaces['mentornity'],
  table: tableListViewConfig.dataConfigs['auth'],
  title: 'User Auth',
  ui: {
    cardConfig: {
      body: {
        fields: [
          {
            fieldId: 'createdAt',
          },
          {
            fieldId: 'google',
          },
          {
            fieldId: 'microsoft',
          },
          {
            fieldId: 'zoom',
          },
        ]
      },
    }
  },
  query: {
    filter: {
      comparison: filter.Comparison.Eq,
      id: 'user._id',
      value: '$userId',
    },
  },
  type: viewConfig$h.AppViewType.DetailViewCard,
  params: {
    userId: {
      required: true,
    },
  },
});

const ID$i = 'detail-view-scheduled-job-send-email';
const viewConfig$b = detailViewConfig.DetailViewConfig.decode({
  _id: ID$i,
  base: 'mentornity',
  space: spaces.spaces['mentornity'],
  table: tableListViewConfig.dataConfigs['scheduledjobs'],
  title: 'Send Email Job',
  ui: {
    cardConfig: {
      body: {
        fields: [
          {
            fieldId: 'name',
          },
          {
            fieldId: 'createdAt',
          },
          {
            fieldId: 'status',
          },
          {
            fieldDisplay: new date.DateField('metadata.sent', 'Sent On').setDateFormat('DD MMM YYYY, HH:mm'),
          },
          {
            fieldDisplay: new date.DateField('metadata.delivered', 'Delivered On').setDateFormat('DD MMM YYYY, HH:mm'),
          },
          {
            fieldDisplay: new date.DateField('metadata.opened', 'Opened On').setDateFormat('DD MMM YYYY, HH:mm'),
          },
          {
            fieldDisplay: new date.DateField('metadata.clicked', 'Clicked On').setDateFormat('DD MMM YYYY, HH:mm'),
          },
          {
            fieldId: 'output',
          },
          {
            fieldId: 'parameters',
          },
        ]
      },
    }
  },
  type: viewConfig$h.AppViewType.DetailViewCard,
  params: {
    itemId: {
      required: true,
    },
  },
});

class AddOrganisationAdminFormHandler {
  constructor() {
    const { jwt, sessionId } = index.getCookieStorage().getAll();
    this.api = instance.createMentornityApiInstance(mentornityApiEndpoint, {
      'Authorization': `Bearer ${jwt}`,
      'Client': 'd2ViLWFkbWlu',
      'Session-Token': sessionId,
    });
  }
  onSubmit(event) {
    const { values: { organisationId, admin: email } } = event.detail;
    return new Promise((resolve, reject) => {
      this.api.importUser(organisationId, 'admins', {
        email,
        firstName: '',
        lastName: '',
        metadata: {},
      }).then(() => {
        resolve({
          events: [
            new actions.InvalidationAction(ID$f, ID$6),
          ],
          navigation: {
            type: 'navigation',
            direction: 'back'
          }
        });
      }).catch(() => {
        reject(['Unexpected error']);
      });
    });
  }
}

function buildQuery(query, quickFilter) {
  let queryFilter = query ? query.filter : undefined;
  if (quickFilter) {
    if (query && query.filter) {
      queryFilter = {
        operator: 'and',
        filters: [query.filter, quickFilter]
      };
    }
    else {
      queryFilter = quickFilter;
    }
  }
  return queryFilter;
}
function generateQuickSearchFilters(quickSearch, filter$1) {
  if (!quickSearch || !filter$1) {
    return undefined;
  }
  return {
    operator: 'or',
    filters: quickSearch.fields.map(field => ({
      comparison: filter.Comparison.Contain,
      id: field.fieldId,
      value: filter$1,
    }))
  };
}
class DvnDataProvider {
  constructor(dataApi, collection, query, initialData, quickSearch) {
    this.didQuickSearchChangeAfterLastFetch = false;
    this.list = listFetchState.ListFetchState.init();
    this.collection = collection;
    this.query = query;
    this.initialData = initialData;
    this.quickSearch = quickSearch;
    this.api = dataApi;
  }
  getInitialData() {
    return this.initialData;
  }
  getData() {
    const { api, collection, query, quickSearchText } = this;
    const self = this;
    return new Promise(((resolve, reject) => {
      if (self.list.data && !this.didQuickSearchChangeAfterLastFetch) {
        // return already fetched data
        resolve(self.list.data);
        return;
      }
      const queryFilter = buildQuery(query, generateQuickSearchFilters(this.quickSearch, quickSearchText));
      api.query(collection, {
        fields: query.fields,
        filter: queryFilter,
        limit: 50,
        skip: 0,
        sort: query.sort,
      }).then(response => {
        self.list = listFetchState.ListFetchState.init().afterFetch(response);
        this.didQuickSearchChangeAfterLastFetch = false;
        resolve(self.list.data);
      }, error => {
        self.list = listFetchState.ListFetchState.init().afterFetchError(error);
        reject(error);
      });
    }));
  }
  setInitialData(initialData) {
    this.initialData = initialData;
  }
  setQuickSearchText(text) {
    this.quickSearchText = text;
    this.didQuickSearchChangeAfterLastFetch = true;
  }
  getQuickSearchText() {
    return this.quickSearchText;
  }
  isQuickSearchEnabled() {
    return !!this.quickSearch;
  }
}

const userDataProvider = (dataApi) => new DvnDataProvider(dataApi, 'users', {
  fields: [
    new index$1.TextField('email', ''),
    new index$1.TextField('firstName', ''),
    new index$1.TextField('lastName', ''),
    new index$1.TextField('status', ''),
  ],
  filter: {
    filters: [
      {
        comparison: filter.Comparison.Eq,
        id: 'status',
        value: 'active',
      },
      {
        comparison: filter.Comparison.Ne,
        id: 'lastName',
        value: '   ',
      },
      {
        comparison: filter.Comparison.Ne,
        id: 'lastName',
        value: '   ',
      },
    ],
    operator: 'and'
  },
  sort: [{ id: 'firstName', order: 1 }]
}, undefined, {
  fields: [
    { fieldId: 'email' },
    { fieldId: 'firstName' },
    { fieldId: 'lastName' },
  ]
});

const ID$h = 'form-view-organisation-admin-add';
const config$6 = (dataApi) => formViewConfig.FormViewConfig.decode({
  _id: ID$h,
  base: 'mentornity',
  title: 'Add New Admin',
  space: spaces.spaces['mentornity'],
  table: tableListViewConfig.dataConfigs['users'],
  type: viewConfig$h.AppViewType.FormView,
  handler: new AddOrganisationAdminFormHandler(),
  ui: {
    fields: [
      // this field is passed by the parameters. this is a data holder field to pass the data to form handler
      {
        field: new dataTransferField.DataTransferField('organisationId'),
      },
      {
        field: new index$2.SingleChoiceField('admin', '', undefined, '', 'select').setDataProvider(userDataProvider(dataApi))
          .setDataAdapter(new tableListViewConfig.DvnDataAdapter('firstName+lastName', 'email'))
          .require(),
      },
    ],
  },
  params: {
    organisationId: {
      required: true,
    },
  },
});

class RemoveOrganisationAdminFormHandler {
  constructor() {
    const { jwt, sessionId } = index.getCookieStorage().getAll();
    this.api = instance.createMentornityApiInstance(mentornityApiEndpoint, {
      'Authorization': `Bearer ${jwt}`,
      'Client': 'd2ViLWFkbWlu',
      'Session-Token': sessionId,
    });
  }
  onSubmit(event) {
    const { values: { admin: userId, organisationDomain } } = event.detail;
    return new Promise((resolve, reject) => {
      this.api.removeOrganisationAdmin(userId, {
        _roles: [`admin@${organisationDomain}`]
      }).then(() => {
        resolve({
          events: [
            new actions.InvalidationAction(ID$f, ID$6),
          ],
          navigation: {
            type: 'navigation',
            direction: 'back'
          }
        });
      }).catch(() => {
        reject(['Unexpected error']);
      });
    });
  }
}

const ID$g = 'form-view-organisation-admin-remove';
const config$5 = (_dataApi) => formViewConfig.FormViewConfig.decode({
  _id: ID$g,
  base: 'mentornity',
  title: 'Remove Admin',
  space: spaces.spaces['mentornity'],
  table: tableListViewConfig.dataConfigs['users'],
  type: viewConfig$h.AppViewType.FormView,
  handler: new RemoveOrganisationAdminFormHandler(),
  ui: {
    fields: [
      // this field is passed by the parameters. this is a data holder field to pass the data to form handler
      {
        field: new dataTransferField.DataTransferField('organisationDomain'),
      },
      {
        field: new index$2.SingleChoiceField('admin', '', undefined, '', 'select').setDataProvider(new DvnDataProvider(undefined, 'users', {})).setDataAdapter(new tableListViewConfig.DvnDataAdapter('firstName+lastName', '_id'))
          .disable()
          .require(),
      },
    ],
  },
  params: {
    admin: {
      required: true,
    },
    organisationDomain: {
      required: true,
    },
  },
});

class DvnDataProviderTimeZone extends DvnDataProvider {
  constructor() {
    super(undefined, undefined, undefined);
    this.options = [];
    this.filteredOptions = [];
    this.searchText = '';
    timeZones.zoneConfig.forEach(group => {
      group.zones.forEach(zone => {
        this.options.push({
          label: `${zone.name} (${zone.value})`,
          value: zone.value,
        });
      });
    });
    this.filteredOptions = this.options;
  }
  getInitialData() {
    return this.options;
  }
  getData() {
    return Promise.resolve(this.filteredOptions);
  }
  setQuickSearchText(text) {
    this.searchText = text;
    if (text) {
      this.filteredOptions = this.options.filter(option => (option.label.toLocaleLowerCase().includes(text.toLocaleLowerCase())));
    }
    else {
      this.filteredOptions = this.options;
    }
  }
  getQuickSearchText() {
    return this.searchText;
  }
  isQuickSearchEnabled() {
    return true;
  }
}

class CreateOrganisationFormHandler {
  constructor() {
    const { jwt, sessionId } = index.getCookieStorage().getAll();
    this.api = instance.createMentornityApiInstance(mentornityApiEndpoint, {
      'Authorization': `Bearer ${jwt}`,
      'Client': 'd2ViLWFkbWlu',
      'Session-Token': sessionId,
    });
  }
  onSubmit(event) {
    const { values: { admin, sourceOrganisationId, newOrganisationDomain, newOrganisationTitle, timeZone, } } = event.detail;
    return new Promise((resolve, reject) => {
      this.api.cloneOrganisation({
        sourceOrganisationId,
        newOrganisationDomain,
        newOrganisationTitle,
        adminIds: [admin],
        timeZone,
      }).then(() => {
        resolve({
          events: [
            new actions.InvalidationAction(ID$f, ID$5),
          ],
          navigation: {
            type: 'navigation',
            direction: 'back'
          }
        });
      }).catch(error => {
        if (error.data && error.data.message === 'domain-already-exists') {
          reject(['Domain is already used by another program.']);
          return;
        }
        reject(['Unexpected error']);
      });
    });
  }
}

const ID$f = 'form-view-organisation-create';
const config$4 = (dataApi) => formViewConfig.FormViewConfig.decode({
  _id: ID$f,
  base: 'mentornity',
  title: 'Create Organisation',
  space: spaces.spaces['mentornity'],
  table: tableListViewConfig.dataConfigs['organisations'],
  type: viewConfig$h.AppViewType.FormView,
  handler: new CreateOrganisationFormHandler(),
  ui: {
    fields: [
      {
        field: new index$2.SingleChoiceField('sourceOrganisationId', 'Program to clone', undefined, 'Search for a template or another program to clone.', 'select').setDataProvider(new DvnDataProvider(dataApi, 'organisations', {
          fields: [
            new index$1.TextField('domain', 'Domain'),
            new index$1.TextField('title', 'Title'),
          ],
          sort: [{ id: 'title', order: 1 }]
        }, undefined, {
          fields: [
            { fieldId: 'domain' },
            { fieldId: 'title' },
          ]
        })).setDataAdapter(new tableListViewConfig.DvnDataAdapter('title', '_id'))
          .require(),
      },
      {
        field: new index$2.SingleChoiceField('admin', 'Admin', undefined, 'Search and select admins.', 'select').setDataProvider(userDataProvider(dataApi))
          .setDataAdapter(new tableListViewConfig.DvnDataAdapter('firstName+lastName', '_id'))
          .require(),
      },
      {
        field: new index$2.SingleChoiceField('timeZone', 'Time Zone', undefined, 'Time zone of the program. Original program\'s time zone is used if empty.', 'select').setDataProvider(new DvnDataProviderTimeZone())
          .setDataAdapter(new tableListViewConfig.DvnDataAdapter('label', 'value')),
      },
      {
        field: new index$1.TextField('newOrganisationTitle', 'Program name', '', 'Shown to users in the UI, emails and notifications.').addInterceptor('onBlur', new ValidatorLength.ValidatorLength(2, 100))
          .addInterceptor('onSubmit', new formViewConfig.ModifierTrimmer())
          .require(),
      },
      {
        field: new index$1.TextField('newOrganisationDomain', 'Program domain', '', 'Used in the url and visible in browser address bar.').addInterceptor('onBlur', new ModifierRegexCharRemover(' '))
          .addInterceptor('onBlur', new tableListViewConfig.ValidatorRegex('[a-z0-9\-]'))
          .addInterceptor('onBlur', new ValidatorLength.ValidatorLength(2, 100))
          .addInterceptor('onSubmit', new formViewConfig.ModifierTrimmer())
          .require(),
      },
    ],
  }
});

class EditOrganisationConfigFormHandler {
  constructor() {
    const { jwt, sessionId } = index.getCookieStorage().getAll();
    this.api = instance.createMentornityApiInstance(mentornityApiEndpoint, {
      'Authorization': `Bearer ${jwt}`,
      'Client': 'd2ViLWFkbWlu',
      'Session-Token': sessionId,
    });
  }
  onSubmit(event) {
    const { values } = event.detail;
    const { item, membershipForm, pairOverviewAndDetail, adminRoutes: admin, menteeRoutes: mentee, mentorRoutes: mentor, anonymousRoutes: anonymous, } = values;
    const body = {
      routes: {
        admin,
        mentee,
        mentor,
        anonymous,
      },
      webAppConfiguration: {
        membershipForm,
        pairOverviewAndDetail
      }
    };
    console.log('body', body);
    return new Promise((resolve, reject) => {
      this.api.update('configs', item._id, body).then(() => {
        resolve({
          navigation: {
            type: 'navigation',
            direction: 'back'
          }
        });
      }).catch(() => {
        reject(['Unexpected error']);
      });
    });
  }
}

const ID$e = 'form-view-organisation-config-edit';
const viewConfig$a = formViewConfig.FormViewConfig.decode({
  _id: ID$e,
  base: 'mentornity',
  title: 'Edit Configuration',
  space: spaces.spaces['mentornity'],
  table: tableListViewConfig.dataConfigs['configs'],
  type: viewConfig$h.AppViewType.FormView,
  handler: new EditOrganisationConfigFormHandler(),
  ui: {
    fields: [
      // this field is passed by the parameters. this is a data holder field to pass the data to form handler
      {
        field: new dataTransferField.DataTransferField('item'),
      },
      {
        field: new index$3.BooleanField('membershipForm', 'Membership Form', `Shows "My Info" item on the left menu which opens a form page for editing profile, metadata and mentorship in a single form.`),
      },
      {
        field: new index$3.BooleanField('pairOverviewAndDetail', 'Pair Overview and Detail', 'Shows new mentors/mentees and mentor selection page.'),
      },
      {
        field: new index$2.MultipleChoiceField('adminRoutes', 'Admin routes', [
          new index$2.MultipleChoiceFieldOption('Mentors', 'mentors'),
          new index$2.MultipleChoiceFieldOption('Mentees', 'mentees'),
          new index$2.MultipleChoiceFieldOption('Groups', 'groups'),
          new index$2.MultipleChoiceFieldOption('Calendar', 'calendar'),
          new index$2.MultipleChoiceFieldOption('Feedbacks', 'feedbacks'),
          new index$2.MultipleChoiceFieldOption('MeetingGoals', 'meetingGoals'),
          new index$2.MultipleChoiceFieldOption('Announcements', 'announcements'),
          new index$2.MultipleChoiceFieldOption('Reports', 'reports'),
          new index$2.MultipleChoiceFieldOption('Subscriptions', 'subscriptions'),
          new index$2.MultipleChoiceFieldOption('Forms', 'forms'),
          new index$2.MultipleChoiceFieldOption('Applications', 'applications'),
          new index$2.MultipleChoiceFieldOption('Screens', 'viewSettings'),
        ], '', 'select'),
      },
      {
        field: new index$2.MultipleChoiceField('mentorRoutes', 'Mentor routes', [
          new index$2.MultipleChoiceFieldOption('Feed', 'feed'),
          new index$2.MultipleChoiceFieldOption('Mentors', 'mentors'),
          new index$2.MultipleChoiceFieldOption('Mentees', 'mentees'),
          new index$2.MultipleChoiceFieldOption('Groups', 'groups'),
          new index$2.MultipleChoiceFieldOption('Forms', 'forms'),
        ], '', 'select'),
      },
      {
        field: new index$2.MultipleChoiceField('menteeRoutes', 'Mentee routes', [
          new index$2.MultipleChoiceFieldOption('Feed', 'feed'),
          new index$2.MultipleChoiceFieldOption('Mentors', 'mentors'),
          new index$2.MultipleChoiceFieldOption('Mentees', 'mentees'),
          new index$2.MultipleChoiceFieldOption('Groups', 'groups'),
          new index$2.MultipleChoiceFieldOption('Forms', 'forms'),
        ], '', 'select'),
      },
      {
        field: new index$2.MultipleChoiceField('anonymousRoutes', 'Anonymous routes', [
          new index$2.MultipleChoiceFieldOption('Mentors', 'mentors'),
          new index$2.MultipleChoiceFieldOption('Groups', 'groups'),
        ], '', 'select'),
      },
    ],
  },
  query: {
    fields: [
      new dataTransferField.DataTransferField('webAppConfiguration'),
      new dataTransferField.DataTransferField('routes'),
    ],
    filter: {
      comparison: filter.Comparison.Eq,
      id: 'organisation._id',
      value: '$itemId',
    },
  },
  conversionConfig: {
    'item.webAppConfiguration.membershipForm': 'membershipForm',
    'item.webAppConfiguration.pairOverviewAndDetail': 'pairOverviewAndDetail',
    'item.routes.admin': 'adminRoutes',
    'item.routes.mentee': 'menteeRoutes',
    'item.routes.mentor': 'mentorRoutes',
    'item.routes.anonymous': 'anonymousRoutes',
  },
  params: {
    itemId: {
      required: true,
    },
  },
});

const ID$d = 'table-list-view-error-logs';
const config$3 = (dataApi) => tableListViewConfig.TableListViewConfig.decode({
  _id: ID$d,
  type: viewConfig$h.AppViewType.ListViewTable,
  base: 'mentornity',
  title: 'Error Logs',
  space: spaces.spaces['mentornity'],
  table: tableListViewConfig.dataConfigs['errorlogs'],
  query: {
    fields: [
      new dataTransferField.DataTransferField('res'),
      new dataTransferField.DataTransferField('command'),
      new dataTransferField.DataTransferField('status'),
      new dataTransferField.DataTransferField('message'),
      new dataTransferField.DataTransferField('createdAt'),
      new dataTransferField.DataTransferField('status'),
      new index$4.ReferenceField('user', 'User', 'firstName', 'imageUrl', 'users', [
        new attachment.AttachmentField('imageUrl', ''),
        new index$1.TextField('email', 'Email'),
        new index$1.TextField('firstName', 'First Name'),
        new index$1.TextField('lastName', 'Last Name'),
      ], true),
    ],
    filter: {
      filters: [
        {
          comparison: filter.Comparison.Ne,
          id: 'user._id',
          value: '',
        },
      ],
      operator: 'or'
    },
    sort: [{ id: 'createdAt', order: -1 }]
  },
  ui: tableListViewConfig.TableListViewConfig.decode({
    main: {
      actions: [
        {
          ui: {
            name: 'expand',
            buttonType: 'icon-button',
            iconName: 'uil uil-expand-alt',
            view: 'flat'
          },
          data: {
            type: 'navigation',
            direction: 'forward',
            placement: appConfig.ViewPlacement.SideModal,
            viewId: ID$n,
            params: {
              conversionConfig: {
                'item._id': 'id',
              }
            }
          }
        },
      ],
      fields: [
        {
          fieldId: 'createdAt',
          fieldDisplay: new date.DateField('createdAt', 'Date').setDateFormat('DD.MM.YYYY HH:mm').setDataType(date.DateDataType.Unix),
        },
        {
          fieldId: 'user.imageUrl',
          fieldDisplay: new nested.NestedField('user.imageUrl', new attachment.AttachmentField('imageUrl', '').setShape('circle'))
        },
        {
          fieldId: 'user.firstName',
          fieldDisplay: new nested.NestedField('user.firstName', new index$1.TextField('firstName', 'First Name'))
        },
        {
          fieldId: 'user.lastName',
          fieldDisplay: new nested.NestedField('user.lastName', new index$1.TextField('lastName', 'Last Name'))
        },
        {
          fieldId: 'user.email',
          fieldDisplay: new nested.NestedField('user.email', new index$1.TextField('email', 'Email'))
        },
        {
          fieldId: 'status',
        },
        {
          fieldId: 'message',
        },
        {
          fieldId: 'res',
        },
      ],
      columns: {
        'user.imageUrl': {
          width: 50,
        },
        'user.firstName': {
          width: 120,
        },
        'user.lastName': {
          width: 120,
        },
        'user.email': {
          width: 220,
        },
        createdAt: {
          width: 150,
        },
        status: {
          width: 80,
        },
        message: {
          weight: 1,
          width: 180,
        },
        res: {
          weight: 1,
          width: 120,
        },
      },
    },
    quickSearch: {
      fields: [
        {
          field: new index$2.SingleChoiceField('user._id', 'Search user', undefined, '', 'select').setDataProvider(userDataProvider(dataApi))
            .setDataAdapter(new tableListViewConfig.DvnDataAdapter('firstName+lastName', '_id')),
        },
      ],
      fieldUIConfigs: [
        {
          fieldId: 'user._id',
          width: '240px',
        },
        {
          fieldId: 'status',
          width: '150px',
        },
      ],
    },
  }),
});

const ID$c = 'table-list-view-error-logs-anonymous';
const viewConfig$9 = tableListViewConfig.TableListViewConfig.decode({
  _id: ID$c,
  type: viewConfig$h.AppViewType.ListViewTable,
  base: 'mentornity',
  title: 'Anonymous Error Logs',
  space: spaces.spaces['mentornity'],
  table: tableListViewConfig.dataConfigs['errorlogs'],
  query: {
    fields: [
      new dataTransferField.DataTransferField('res'),
      new dataTransferField.DataTransferField('command'),
      new dataTransferField.DataTransferField('status'),
      new dataTransferField.DataTransferField('message'),
      new dataTransferField.DataTransferField('createdAt'),
      new dataTransferField.DataTransferField('status'),
    ],
    filter: {
      filters: [
        {
          comparison: filter.Comparison.Eq,
          id: 'user._id',
          value: '',
        },
      ],
      operator: 'or'
    },
    sort: [{ id: 'createdAt', order: -1 }]
  },
  ui: tableListViewConfig.TableListViewConfig.decode({
    main: {
      actions: [
        {
          ui: {
            name: 'expand',
            buttonType: 'icon-button',
            iconName: 'uil uil-expand-alt',
            view: 'flat'
          },
          data: {
            type: 'navigation',
            direction: 'forward',
            placement: appConfig.ViewPlacement.SideModal,
            viewId: ID$n,
            params: {
              conversionConfig: {
                'item._id': 'id',
              }
            }
          }
        },
      ],
      fields: [
        {
          fieldId: 'createdAt',
          fieldDisplay: new date.DateField('createdAt', 'Creation Date').setDateFormat('DD.MM.YYYY HH:mm').setDataType(date.DateDataType.Unix),
        },
        {
          fieldId: 'status',
        },
        {
          fieldId: 'message',
        },
        {
          fieldId: 'res',
        },
      ],
      columns: {
        createdAt: {
          width: 150,
        },
        status: {
          width: 100,
        },
      },
    },
  }),
});

const ID$b = 'table-list-view-form-response-contact';
const formTableListViewUIConfig = tableListViewConfig.TableListViewConfig.decode({
  main: {
    actions: [{
        ui: {
          name: 'expand',
          buttonType: 'icon-button',
          iconName: 'uil uil-expand-alt',
          view: 'flat'
        },
        data: {
          type: 'navigation',
          direction: 'forward',
          placement: appConfig.ViewPlacement.SideModal,
          viewId: ID$k,
          params: {
            conversionConfig: {
              'item._id': 'itemId',
            }
          }
        }
      }],
    fields: [
      {
        fieldId: 'createdAt',
        fieldDisplay: new date.DateField('createdAt', 'Date').setDateFormat('DD MMM HH:mm').setDataType(date.DateDataType.Unix),
      },
      {
        fieldId: 'data.phone',
        fieldDisplay: new nested.NestedField('data.phone', new index$1.TextField('phone', 'Phone')),
      },
      {
        fieldId: 'data.email',
        fieldDisplay: new nested.NestedField('data.email', new index$1.TextField('email', 'Email')),
      },
      {
        fieldId: 'data.fullName',
        fieldDisplay: new nested.NestedField('data.fullName', new index$1.TextField('name', 'Name')),
      },
      {
        fieldId: 'data.message',
        fieldDisplay: new nested.NestedField('data.message', new index$1.TextField('message', 'Message')),
      },
    ],
    columns: {
      createdAt: {
        width: 120,
      },
      'data.phone': {
        width: 140,
      },
      'data.email': {
        width: 200,
      },
      'data.fullName': {
        width: 180,
      },
      'data.message': {
        weight: 1,
        width: 200,
      },
    },
  },
  quickSearch: {
    fields: [
      { field: new index$1.TextField('data.name', 'Name') },
      { field: new index$1.TextField('data.email', 'Email') },
      { field: new index$1.TextField('data.message', 'Message') },
    ]
  },
});
const viewConfig$8 = tableListViewConfig.TableListViewConfig.decode({
  _id: ID$b,
  type: viewConfig$h.AppViewType.ListViewTable,
  base: 'mentornity',
  title: 'Contact Forms',
  space: spaces.spaces['mentornity'],
  table: tableListViewConfig.dataConfigs['formResponses'],
  query: {
    fields: [
      new date.DateField('createdAt', 'Created At'),
      new index$1.TextField('data', 'Data'),
      new index$1.TextField('type', 'type'),
    ],
    filter: {
      filters: [
        {
          comparison: filter.Comparison.Eq,
          id: 'type',
          value: 'contact',
        },
      ],
      operator: 'or'
    },
    sort: [{ id: 'createdAt', order: -1 }]
  },
  ui: formTableListViewUIConfig,
});

const ID$a = 'table-list-view-form-response-help';
const viewConfig$7 = tableListViewConfig.TableListViewConfig.decode({
  _id: ID$a,
  type: viewConfig$h.AppViewType.ListViewTable,
  base: 'mentornity',
  title: 'Help Forms',
  space: spaces.spaces['mentornity'],
  table: tableListViewConfig.dataConfigs['formResponses'],
  query: {
    fields: [
      new date.DateField('createdAt', 'Created At'),
      new index$1.TextField('data', 'Data'),
      new index$1.TextField('type', 'type'),
    ],
    filter: {
      filters: [
        {
          comparison: filter.Comparison.Eq,
          id: 'type',
          value: 'help',
        },
      ],
      operator: 'or'
    },
    sort: [{ id: 'createdAt', order: -1 }]
  },
  ui: formTableListViewUIConfig,
});

const ID$9 = 'table-list-view-scheduled-job-sync-events-google';
const config$2 = (dataApi) => tableListViewConfig.TableListViewConfig.decode({
  _id: ID$9,
  type: viewConfig$h.AppViewType.ListViewTable,
  base: 'mentornity',
  title: 'Sync Google Events Jobs',
  space: spaces.spaces['mentornity'],
  table: tableListViewConfig.dataConfigs['scheduledjobs'],
  query: {
    fields: [
      new index$1.TextField('name', 'Name'),
      new index$1.TextField('status', 'Status'),
      new date.DateField('scheduledAt', 'Created At'),
      new date.DateField('createdAt', 'Created At'),
      new dataTransferField.DataTransferField('parameters'),
      new dataTransferField.DataTransferField('metadata'),
    ],
    filter: {
      filters: [
        {
          comparison: filter.Comparison.Eq,
          id: 'name',
          value: 'CreateEventInGoogle',
        },
      ],
      operator: 'or'
    },
    sort: [{ id: 'createdAt', order: -1 }]
  },
  ui: tableListViewConfig.TableListViewConfig.decode({
    main: {
      actions: [{
          ui: {
            name: 'expand',
            buttonType: 'icon-button',
            iconName: 'uil uil-expand-alt',
            view: 'flat'
          },
          data: {
            type: 'navigation',
            direction: 'forward',
            placement: appConfig.ViewPlacement.SideModal,
            viewId: ID$i,
            params: {
              conversionConfig: {
                'item._id': 'itemId',
              }
            }
          }
        }],
      fields: [
        {
          fieldId: 'createdAt',
          fieldDisplay: new date.DateField('createdAt', 'Date').setDateFormat('DD MMM YYYY').setDataType(date.DateDataType.Unix),
        },
        {
          fieldId: 'createdAt',
          fieldDisplay: new date.DateField('createdAt', 'Hour').setDateFormat('HH:mm').setDataType(date.DateDataType.Unix),
        },
        {
          fieldId: 'parameters.googleEvent.summary',
          fieldDisplay: new nested.NestedField('parameters.googleEvent.summary', new index$1.TextField('summary', 'Summary')),
        },
        {
          fieldId: 'parameters.googleEvent.start.dateTime',
          fieldDisplay: new nested.NestedField('parameters.googleEvent.start.dateTime', new date.DateField('meetingStart', 'Meeting Start').setDateFormat('DD MMM HH:mm')),
        },
        {
          fieldId: 'parameters.googleEvent.end.dateTime',
          fieldDisplay: new nested.NestedField('parameters.googleEvent.end.dateTime', new date.DateField('meetingEnd', 'Meeting End').setDateFormat('DD MMM HH:mm')),
        },
        {
          fieldId: 'status',
        },
      ],
      columns: {
        createdAt: {
          width: 120,
        },
        'parameters.googleEvent.start.dateTime': {
          width: 150,
        },
        'parameters.googleEvent.end.dateTime': {
          width: 150,
        },
        status: {
          width: 100,
        },
      },
    },
    quickSearch: {
      fields: [
        {
          field: new index$2.SingleChoiceField('parameters.userId', 'Search user', undefined, 'Search and select admins.', 'select').setDataProvider(userDataProvider(dataApi))
            .setDataAdapter(new tableListViewConfig.DvnDataAdapter('firstName+lastName', '_id')),
        },
        {
          field: new index$2.SingleChoiceField('status', 'Status', [
            new index$2.SingleChoiceFieldOption('Done', 'done'),
            new index$2.SingleChoiceFieldOption('Failed', 'failed'),
          ]),
        }
      ],
      fieldUIConfigs: [
        {
          fieldId: 'parameters.userId',
          width: '256px',
        },
      ],
      requireFilters: false,
    },
  }),
});

const ID$8 = 'table-list-view-scheduled-job-sync-events-microsoft';
const config$1 = (dataApi) => tableListViewConfig.TableListViewConfig.decode({
  _id: ID$8,
  type: viewConfig$h.AppViewType.ListViewTable,
  base: 'mentornity',
  title: 'Sync Microsoft Events Jobs',
  space: spaces.spaces['mentornity'],
  table: tableListViewConfig.dataConfigs['scheduledjobs'],
  query: {
    fields: [
      new index$1.TextField('_id', 'ID'),
      new index$1.TextField('name', 'Name'),
      new index$1.TextField('status', 'Status'),
      new date.DateField('scheduledAt', 'Created At'),
      new date.DateField('createdAt', 'Created At'),
      new dataTransferField.DataTransferField('parameters'),
      new dataTransferField.DataTransferField('metadata'),
    ],
    filter: {
      filters: [
        {
          comparison: filter.Comparison.Eq,
          id: 'name',
          value: 'CreateEventInMicrosoft',
        },
      ],
      operator: 'or'
    },
    sort: [{ id: 'createdAt', order: -1 }]
  },
  ui: tableListViewConfig.TableListViewConfig.decode({
    main: {
      actions: [{
          ui: {
            name: 'expand',
            buttonType: 'icon-button',
            iconName: 'uil uil-expand-alt',
            view: 'flat'
          },
          data: {
            type: 'navigation',
            direction: 'forward',
            placement: appConfig.ViewPlacement.SideModal,
            viewId: ID$i,
            params: {
              conversionConfig: {
                'item._id': 'itemId',
              }
            }
          }
        }],
      fields: [
        {
          fieldId: 'createdAt',
          fieldDisplay: new date.DateField('createdAt', 'Date').setDateFormat('DD MMM YYYY').setDataType(date.DateDataType.Unix),
        },
        {
          fieldId: 'createdAt',
          fieldDisplay: new date.DateField('createdAt', 'Hour').setDateFormat('HH:mm').setDataType(date.DateDataType.Unix),
        },
        {
          fieldId: 'parameters.microsoftEvent.subject',
          fieldDisplay: new nested.NestedField('parameters.microsoftEvent.subject', new index$1.TextField('summary', 'Subject')),
        },
        {
          fieldId: 'parameters.microsoftEvent.start.dateTime',
          fieldDisplay: new nested.NestedField('parameters.microsoftEvent.start.dateTime', new date.DateField('meetingStart', 'Meeting Start').setDateFormat('DD MMM HH:mm')),
        },
        {
          fieldId: 'parameters.microsoftEvent.end.dateTime',
          fieldDisplay: new nested.NestedField('parameters.microsoftEvent.end.dateTime', new date.DateField('meetingEnd', 'Meeting End').setDateFormat('DD MMM HH:mm')),
        },
        {
          fieldId: 'status',
        },
      ],
      columns: {
        createdAt: {
          width: 120,
        },
        'parameters.microsoftEvent.start.dateTime': {
          width: 150,
        },
        'parameters.microsoftEvent.end.dateTime': {
          width: 150,
        },
        status: {
          width: 100,
        },
      },
    },
    quickSearch: {
      fields: [
        {
          field: new index$2.SingleChoiceField('parameters.userId', 'Search user', undefined, 'Search and select admins.', 'select').setDataProvider(userDataProvider(dataApi))
            .setDataAdapter(new tableListViewConfig.DvnDataAdapter('firstName+lastName', '_id'))
        },
        {
          field: new index$2.SingleChoiceField('status', 'Status', [
            new index$2.SingleChoiceFieldOption('Done', 'done'),
            new index$2.SingleChoiceFieldOption('Failed', 'failed'),
          ]),
        }
      ],
      fieldUIConfigs: [
        {
          fieldId: 'parameters.userId',
          width: '256px',
        },
      ],
      requireFilters: false,
    },
  }),
});

const ID$7 = 'table-list-view-scheduled-job-send-email';
const tableListViewUIConfigScheduledJobs = tableListViewConfig.TableListViewConfig.decode({
  main: {
    actions: [{
        ui: {
          name: 'expand',
          buttonType: 'icon-button',
          iconName: 'uil uil-expand-alt',
          view: 'flat'
        },
        data: {
          type: 'navigation',
          direction: 'forward',
          placement: appConfig.ViewPlacement.SideModal,
          viewId: ID$i,
          params: {
            conversionConfig: {
              'item._id': 'itemId',
            }
          }
        }
      }],
    fields: [
      {
        fieldId: 'parameters.templateAndSubjectName',
        fieldDisplay: new nested.NestedField('parameters.templateAndSubjectName', new index$1.TextField('templateAndSubjectName', 'Type')),
      },
      {
        fieldId: 'createdAt',
        fieldDisplay: new date.DateField('createdAt', 'Date').setDateFormat('DD MMM YYYY').setDataType(date.DateDataType.Unix),
      },
      {
        fieldId: 'createdAt',
        fieldDisplay: new date.DateField('createdAt', 'Hour').setDateFormat('HH:mm').setDataType(date.DateDataType.Unix),
      },
      {
        fieldId: 'parameters.senderName',
        fieldDisplay: new nested.NestedField('parameters.senderName', new index$1.TextField('senderName', 'Sender')),
      },
      {
        fieldId: 'parameters.recipientEmail',
        fieldDisplay: new nested.NestedField('parameters.recipientEmail', new index$1.TextField('recipientEmail', 'Recipient')),
      },
      {
        fieldId: 'metadata.sent',
        fieldDisplay: new nested.NestedField('metadata.sent', new date.DateField('sentOn', 'Sent On').setDateFormat('DD MMM HH:mm')),
      },
      {
        fieldId: 'metadata.delivered',
        fieldDisplay: new nested.NestedField('metadata.delivered', new date.DateField('deliveredOn', 'Delivered On').setDateFormat('DD MMM HH:mm')),
      },
      {
        fieldId: 'status',
      },
    ],
    columns: {
      createdAt: {
        width: 100,
      },
      status: {
        width: 100,
      },
    },
  },
  quickSearch: {
    fields: [
      { field: new index$1.TextField('parameters.recipientEmail', 'Recipient') },
      {
        field: new index$2.SingleChoiceField('parameters.templateAndSubjectName', 'Type', [
          new index$2.SingleChoiceFieldOption('Announcement', 'Announcement'),
          new index$2.SingleChoiceFieldOption('Accept Pair Request', 'AcceptSubscription'),
          new index$2.SingleChoiceFieldOption('Reject Pair Request', 'RejectSubscription'),
          new index$2.SingleChoiceFieldOption('New Pair', 'CreateSubscription'),
          new index$2.SingleChoiceFieldOption('New Availability', 'CreateAvailability'),
          new index$2.SingleChoiceFieldOption('Cancel Meeting', 'CancelEvent'),
          new index$2.SingleChoiceFieldOption('New Meeting', 'CreateEvent'),
          new index$2.SingleChoiceFieldOption('New Meeting for Goal', 'CreateEventForMeetingGoal'),
          new index$2.SingleChoiceFieldOption('Update Meeting', 'UpdateEvent'),
          new index$2.SingleChoiceFieldOption('Invitation', 'Invitation'),
          new index$2.SingleChoiceFieldOption('New Form Assignment', 'FormAssignment'),
          new index$2.SingleChoiceFieldOption('New Group Member', 'NewGroupMember'),
          new index$2.SingleChoiceFieldOption('New Message', 'NewMessage'),
          new index$2.SingleChoiceFieldOption('Reset Password Link', 'ResetPasswordLink'),
        ]),
      }
    ],
    fieldUIConfigs: [
      {
        fieldId: 'parameters.templateAndSubjectName',
        width: '240px',
      },
    ],
    requireFilters: true,
  },
});
const viewConfig$6 = tableListViewConfig.TableListViewConfig.decode({
  _id: ID$7,
  type: viewConfig$h.AppViewType.ListViewTable,
  base: 'mentornity',
  title: 'Send Email Jobs',
  space: spaces.spaces['mentornity'],
  table: tableListViewConfig.dataConfigs['scheduledjobs'],
  query: {
    fields: [
      new index$1.TextField('name', 'Name'),
      new index$1.TextField('status', 'Status'),
      new date.DateField('scheduledAt', 'Created At'),
      new date.DateField('createdAt', 'Created At'),
      new dataTransferField.DataTransferField('parameters'),
      new dataTransferField.DataTransferField('metadata'),
    ],
    filter: {
      filters: [
        {
          comparison: filter.Comparison.Eq,
          id: 'name',
          value: 'SendEmail',
        },
      ],
      operator: 'or'
    },
    sort: [{ id: 'createdAt', order: -1 }]
  },
  ui: tableListViewUIConfigScheduledJobs,
});

const ID$6 = 'table-list-view-organisation-admins';
const organisationTableListViewUIConfig$1 = tableListViewConfig.TableListViewConfig.decode({
  header: {
    actions: [{
        ui: {
          name: 'add-admin',
          buttonType: 'button',
          label: 'Add New'
        },
        data: {
          type: 'navigation',
          direction: 'forward',
          placement: appConfig.ViewPlacement.Dialog,
          viewId: ID$h,
          params: {
            conversionConfig: {
              'organisationId': 'organisationId',
              'organisationDomain': 'organisationDomain',
            }
          }
        }
      }],
  },
  leanedHorizontally: false,
  main: {
    actions: [
      {
        ui: {
          name: 'remove-admins',
          buttonType: 'icon-button',
          iconName: 'uil uil-trash-alt',
          tint: 'danger',
          view: 'flat'
        },
        data: {
          type: 'navigation',
          direction: 'forward',
          placement: appConfig.ViewPlacement.Dialog,
          viewId: ID$g,
          params: {
            conversionConfig: {
              'item': 'admin',
              'organisationDomain': 'organisationDomain',
            }
          }
        }
      },
    ],
    fields: [
      { fieldId: 'imageUrl' },
      { fieldId: 'firstName' },
      { fieldId: 'lastName' },
      { fieldId: 'email' },
    ],
    columns: {
      firstName: {
        width: 150,
      },
      imageUrl: {
        width: 50,
      },
      lastName: {
        width: 150,
      },
    },
  },
});
const viewConfig$5 = tableListViewConfig.TableListViewConfig.decode({
  _id: ID$6,
  type: viewConfig$h.AppViewType.ListViewTable,
  base: 'mentornity',
  title: 'Admins',
  space: spaces.spaces['mentornity'],
  table: tableListViewConfig.dataConfigs['users'],
  query: {
    fields: [
      new dataTransferField.DataTransferField('imageUrl'),
      new dataTransferField.DataTransferField('firstName'),
      new dataTransferField.DataTransferField('lastName'),
      new dataTransferField.DataTransferField('email'),
    ],
    filter: {
      comparison: filter.Comparison.Eq,
      id: '_roles',
      value: 'admin@+$organisationDomain',
    },
    sort: [{ id: 'firstName', order: 1 }]
  },
  ui: organisationTableListViewUIConfig$1,
  params: {
    organisationDomain: {
      required: true,
    },
    organisationId: {
      required: true,
    },
  },
});

const ID$5 = 'table-list-view-organisation';
const organisationTableListViewUIConfig = tableListViewConfig.TableListViewConfig.decode({
  header: {
    actions: [{
        ui: {
          name: 'new-organisation',
          buttonType: 'button',
          label: 'Create New'
        },
        data: {
          type: 'navigation',
          direction: 'forward',
          placement: appConfig.ViewPlacement.Dialog,
          viewId: ID$f,
        }
      }],
  },
  main: {
    actions: [
      {
        ui: {
          name: 'expand',
          buttonType: 'icon-button',
          iconName: 'uil uil-expand-alt',
          view: 'flat'
        },
        data: {
          type: 'navigation',
          direction: 'forward',
          placement: appConfig.ViewPlacement.SideModal,
          viewId: ID$l,
          params: {
            conversionConfig: {
              'item._id': 'itemId',
            }
          }
        }
      },
      {
        ui: {
          name: 'manage-admins',
          buttonType: 'icon-button',
          iconName: 'uil uil-users-alt',
          view: 'flat'
        },
        data: {
          type: 'navigation',
          direction: 'forward',
          placement: appConfig.ViewPlacement.SideModal,
          viewId: ID$6,
          params: {
            conversionConfig: {
              'item._id': 'organisationId',
              'item.domain': 'organisationDomain',
            }
          }
        }
      },
      {
        ui: {
          name: 'expand',
          buttonType: 'icon-button',
          iconName: 'uil uil-cog',
          view: 'flat'
        },
        data: {
          type: 'navigation',
          direction: 'forward',
          placement: appConfig.ViewPlacement.SideModal,
          viewId: ID$e,
          params: {
            conversionConfig: {
              'item._id': 'itemId',
            }
          }
        }
      },
    ],
    fields: [
      { fieldId: 'logoUrl' },
      { fieldId: 'status', isEditable: true },
      { fieldId: 'model', isEditable: true },
      { fieldId: 'title' },
      {
        fieldDisplay: new date.DateField('createdAt', 'Creation Date')
          .setDateFormat('DD MMM YYYY')
          .setDataType(date.DateDataType.Unix),
      },
      {
        fieldDisplay: new index$1.TextField('summary.metrics.mentorCount', 'Mentors'),
      },
      {
        fieldDisplay: new index$1.TextField('summary.metrics.menteeCount', 'Mentees'),
      },
    ],
    columns: {
      title: {
        weight: 1,
        width: 300,
      },
      status: {
        width: 100,
      },
      model: {
        width: 180,
      },
      logoUrl: {
        width: 50,
      },
      createdAt: {
        width: 150,
      },
      'summary.metrics.mentorCount': {
        width: 100,
      },
      'summary.metrics.menteeCount': {
        width: 100,
      },
    },
  },
  quickSearch: {
    fields: [
      { fieldId: 'domain' },
      { fieldId: 'title' },
      { fieldId: 'status' },
      { fieldId: 'model' },
    ],
    fieldUIConfigs: [
      {
        fieldId: 'model',
        width: '200px',
      },
    ],
    ui: {
      model: {
        width: '200px'
      }
    }
  },
});
const viewConfig$4 = tableListViewConfig.TableListViewConfig.decode({
  _id: ID$5,
  type: viewConfig$h.AppViewType.ListViewTable,
  base: 'mentornity',
  title: 'Organisations',
  space: spaces.spaces['mentornity'],
  table: tableListViewConfig.dataConfigs['organisations'],
  query: {
    fields: [
      new dataTransferField.DataTransferField('status'),
      new dataTransferField.DataTransferField('model'),
      new dataTransferField.DataTransferField('logoUrl'),
      new dataTransferField.DataTransferField('domain'),
      new dataTransferField.DataTransferField('title'),
      new dataTransferField.DataTransferField('description'),
      new dataTransferField.DataTransferField('createdAt'),
      {
        type: 'reverse-reference',
        id: 'summary',
        otherCollection: 'organisationSummaries',
        nameInOtherCollection: 'organisation',
        isSingle: true,
        fields: [{ id: 'metrics' }]
      }
    ],
    sort: [{ id: 'createdAt', order: -1 }]
  },
  ui: organisationTableListViewUIConfig,
});

const ID$4 = 'table-list-view-scheduled-job-next-day-summary';
const tableListViewUIConfigScheduledJobsNextDaySummary = tableListViewConfig.TableListViewConfig.decode({
  main: {
    fields: [
      {
        fieldId: 'createdAt',
        fieldDisplay: new date.DateField('createdAt', 'Creation Date').setDateFormat('DD MMM YYYY HH:mm').setDataType(date.DateDataType.Unix),
      },
      {
        fieldId: 'scheduledAt',
        fieldDisplay: new date.DateField('scheduledAt', 'Scheduled Date').setDateFormat('DD MMM YYYY HH:mm'),
      },
      {
        fieldId: 'status',
      },
    ],
    columns: {
      createdAt: {
        width: 250,
      },
      scheduledAt: {
        width: 250,
      },
      'status': {
        width: 200,
      },
    },
  },
});
const viewConfig$3 = tableListViewConfig.TableListViewConfig.decode({
  _id: ID$4,
  type: viewConfig$h.AppViewType.ListViewTable,
  base: 'mentornity',
  title: 'Next Day Events Summary Jobs',
  space: spaces.spaces['mentornity'],
  table: tableListViewConfig.dataConfigs['scheduledjobs'],
  query: {
    fields: [
      new index$1.TextField('name', 'Name'),
      new index$1.TextField('status', 'Status'),
      new date.DateField('scheduledAt', 'Created At'),
      new date.DateField('createdAt', 'Created At'),
    ],
    filter: {
      filters: [
        {
          comparison: filter.Comparison.Eq,
          id: 'name',
          value: 'NotificationNextDayEventsSummary',
        },
      ],
      operator: 'or'
    },
    sort: [{ id: 'createdAt', order: -1 }]
  },
  ui: tableListViewUIConfigScheduledJobsNextDaySummary,
});

const ID$3 = 'table-list-view-scheduled-job-daily-summary';
const viewConfig$2 = tableListViewConfig.TableListViewConfig.decode({
  _id: ID$3,
  type: viewConfig$h.AppViewType.ListViewTable,
  base: 'mentornity',
  title: 'Daily Events Summary Jobs',
  space: spaces.spaces['mentornity'],
  table: tableListViewConfig.dataConfigs['scheduledjobs'],
  query: {
    fields: [
      new index$1.TextField('name', 'Name'),
      new index$1.TextField('status', 'Status'),
      new date.DateField('scheduledAt', 'Created At'),
      new date.DateField('createdAt', 'Created At'),
    ],
    filter: {
      filters: [
        {
          comparison: filter.Comparison.Eq,
          id: 'name',
          value: 'NotificationDailyEventSummary',
        },
      ],
      operator: 'or'
    },
    sort: [{ id: 'createdAt', order: -1 }]
  },
  ui: tableListViewUIConfigScheduledJobsNextDaySummary,
});

const ID$2 = 'table-list-view-session';
const config = (dataApi) => tableListViewConfig.TableListViewConfig.decode({
  _id: ID$2,
  type: viewConfig$h.AppViewType.ListViewTable,
  base: 'mentornity',
  title: 'User Sessions',
  space: spaces.spaces['mentornity'],
  table: tableListViewConfig.dataConfigs['sessions'],
  query: {
    fields: [
      new dataTransferField.DataTransferField('client'),
      new dataTransferField.DataTransferField('createdAt'),
      new dataTransferField.DataTransferField('updatedAt'),
      new dataTransferField.DataTransferField('failureReason'),
      new dataTransferField.DataTransferField('status'),
      new index$4.ReferenceField('user', 'User', 'firstName', 'imageUrl', 'users', [
        new attachment.AttachmentField('imageUrl', ''),
        new index$1.TextField('email', 'Email'),
        new index$1.TextField('firstName', 'First Name'),
        new index$1.TextField('lastName', 'Last Name'),
      ], true),
    ],
    sort: [{ id: 'updatedAt', order: -1 }]
  },
  ui: tableListViewConfig.TableListViewConfig.decode({
    header: {
      actions: [],
    },
    main: {
      actions: [],
      fields: [
        {
          fieldId: 'user.imageUrl',
          fieldDisplay: new nested.NestedField('user.imageUrl', new attachment.AttachmentField('imageUrl', '').setShape('circle'))
        },
        {
          fieldId: 'user.firstName',
          fieldDisplay: new nested.NestedField('user.firstName', new index$1.TextField('firstName', 'First Name'))
        },
        {
          fieldId: 'user.lastName',
          fieldDisplay: new nested.NestedField('user.lastName', new index$1.TextField('lastName', 'Last Name'))
        },
        {
          fieldId: 'user.email',
          fieldDisplay: new nested.NestedField('user.email', new index$1.TextField('email', 'Email'))
        },
        { fieldId: 'createdAt' },
        { fieldId: 'updatedAt' },
        { fieldId: 'client' },
        { fieldId: 'status' },
        { fieldId: 'failureReason' },
      ],
      columns: {
        'user.imageUrl': {
          width: 50,
        },
        'user.firstName': {
          width: 120,
        },
        'user.lastName': {
          width: 120,
        },
        'user.email': {
          width: 240,
        },
        createdAt: {
          width: 150,
        },
        updatedAt: {
          width: 150,
        },
        status: {
          width: 150,
        },
        client: {
          width: 120,
        },
        failureReason: {
          weight: 1,
          width: 240,
        },
      },
    },
    quickSearch: {
      fields: [
        {
          field: new index$2.SingleChoiceField('user._id', 'Search user', undefined, '', 'select').setDataProvider(userDataProvider(dataApi))
            .setDataAdapter(new tableListViewConfig.DvnDataAdapter('firstName+lastName', '_id')),
        },
        {
          field: new index$2.SingleChoiceField('status', 'Status', [
            new index$2.SingleChoiceFieldOption('Successful', 'successful'),
            new index$2.SingleChoiceFieldOption('Failed', 'failed'),
            new index$2.SingleChoiceFieldOption('Logged Out', 'loggedOut'),
          ]),
        }
      ],
      fieldUIConfigs: [
        {
          fieldId: 'user._id',
          width: '240px',
        },
        {
          fieldId: 'status',
          width: '150px',
        },
      ],
    },
  }),
});

const ID$1 = 'table-list-view-user';
const listViewUIConfig = tableListViewConfig.TableListViewConfig.decode({
  header: {
    actions: [],
  },
  main: {
    actions: [
      {
        ui: {
          name: 'expand',
          buttonType: 'icon-button',
          iconName: 'uil uil-key-skeleton',
          view: 'flat'
        },
        data: {
          type: 'navigation',
          direction: 'forward',
          placement: appConfig.ViewPlacement.SideModal,
          viewId: ID$j,
          params: {
            conversionConfig: {
              'item._id': 'userId',
            }
          }
        }
      },
    ],
    fields: [
      { fieldId: 'imageUrl' },
      { fieldId: 'firstName' },
      { fieldId: 'lastName' },
      { fieldId: 'email' },
      { fieldId: 'status' },
      { fieldId: 'createdAt' },
      {
        fieldId: 'lastSession.updatedAt',
        fieldDisplay: new nested.NestedField('lastSession.updatedAt', new date.DateField('updatedAt', 'Last Session')
          .setDataType(date.DateDataType.Unix)
          .setDateFormat('DD MMM YYYY HH:mm')),
      },
      { fieldId: 'memberships' },
      { fieldId: '_id' },
    ],
    columns: {
      _id: {
        width: 256,
      },
      createdAt: {
        width: 120,
      },
      email: {
        width: 240,
      },
      firstName: {
        width: 150,
      },
      imageUrl: {
        width: 50,
      },
      lastName: {
        width: 150,
      },
      'lastSession.updatedAt': {
        width: 200,
      },
      status: {
        width: 100,
      },
      memberships: {
        weight: 1,
      },
    },
  },
  quickSearch: {
    fields: [
      { fieldId: 'email' },
      { fieldId: 'firstName' },
      { fieldId: 'lastName' },
      { fieldId: 'status' },
    ]
  },
});
const viewConfig$1 = tableListViewConfig.TableListViewConfig.decode({
  _id: ID$1,
  type: viewConfig$h.AppViewType.ListViewTable,
  base: 'mentornity',
  title: 'Users',
  space: spaces.spaces['mentornity'],
  table: tableListViewConfig.dataConfigs['users'],
  query: {
    fields: [
      new date.DateField('createdAt', 'Created At').setDataType(date.DateDataType.Unix).setDateFormat('DD MMM YYYY'),
      new attachment.AttachmentField('imageUrl', ''),
      new index$1.TextField('email', 'Email'),
      new index$1.TextField('firstName', 'First Name'),
      new index$1.TextField('lastName', 'Last Name'),
      new index$1.TextField('status', 'Status'),
      new tableListViewConfig.RelationReferenceField('memberships', 'Programs', 'title', 'logoUrl', 'memberships', 'user', 'organisations', 'organisation', [
        new index$1.TextField('status', '')
      ], [
        new index$1.TextField('logoUrl', ''),
        new index$1.TextField('title', ''),
      ]),
      {
        type: 'reverse-reference',
        id: 'lastSession',
        otherCollection: 'sessions',
        nameInOtherCollection: 'user',
        isSingle: true,
        fields: [{ id: 'updatedAt' }, { id: 'createdAt' }],
        limit: 1,
        sort: {
          order: -1,
          id: 'updatedAt'
        }
      }
    ],
    sort: [{ id: 'createdAt', order: -1 }]
  },
  ui: listViewUIConfig,
});

const ID = 'table-list-view-white-label';
const viewConfig = tableListViewConfig.TableListViewConfig.decode({
  _id: ID,
  type: viewConfig$h.AppViewType.ListViewTable,
  base: 'mentornity',
  title: 'White Labels',
  space: spaces.spaces['mentornity'],
  table: tableListViewConfig.dataConfigs['whiteLabels'],
  query: {
    fields: [
      new dataTransferField.DataTransferField('title'),
      new dataTransferField.DataTransferField('domain'),
      new dataTransferField.DataTransferField('createdAt'),
    ],
    sort: [{ id: 'title', order: 1 }]
  },
  ui: tableListViewConfig.TableListViewConfig.decode({
    main: {
      fields: [
        { fieldId: 'title' },
        { fieldId: 'domain' },
        {
          fieldId: 'createdAt',
          fieldDisplay: new date.DateField('createdAt', 'Date').setDateFormat('DD MMM YYYY').setDataType(date.DateDataType.Unix),
        },
      ],
      columns: {
        domain: {
          weight: 1,
        },
        title: {
          weight: 1,
        },
        createdAt: {
          width: 150,
        },
      },
    },
  }),
});

const dataApi = new dataApi$1.DataApiImpl(dataApiEndpoint, { Authorization: `Bearer ${index.getSessionData().token}` });
const appConfigs = {
  // app for system admins
  'app-configs-system-admin': appConfig.AppConfig.decode({
    _id: 'app-configs-system-admin',
    _created: new Date(),
    _updated: new Date(),
    mainContent: {
      centered: false,
    },
    mainNavigation: {
      items: [
        {
          ui: {
            icon: 'uil-building',
            title: 'Organisations',
          },
          viewId: ID$5,
        },
        {
          ui: {
            icon: 'uil-clock',
            parent: 'Scheduled Jobs',
            title: 'Send Email'
          },
          viewId: ID$7,
        },
        {
          ui: {
            icon: 'uil-clock',
            parent: 'Scheduled Jobs',
            title: 'Sync Google'
          },
          viewId: ID$9,
        },
        {
          ui: {
            icon: 'uil-clock',
            parent: 'Scheduled Jobs',
            title: 'Sync Microsoft'
          },
          viewId: ID$8,
        },
        {
          ui: {
            icon: 'uil-clock',
            parent: 'Scheduled Jobs',
            title: 'Next Day Summary'
          },
          viewId: ID$4,
        },
        {
          ui: {
            icon: 'uil-clock',
            parent: 'Scheduled Jobs',
            title: 'Daily Summary'
          },
          viewId: ID$3,
        },
        {
          ui: {
            icon: 'uil-signin',
            title: 'Sessions'
          },
          viewId: ID$2,
        },
        {
          ui: {
            icon: 'uil-file-alt',
            title: 'Contact',
            parent: 'Support Forms',
          },
          viewId: ID$b,
        },
        {
          ui: {
            icon: 'uil-file-alt',
            title: 'Help',
            parent: 'Support Forms',
          },
          viewId: ID$a,
        },
        {
          ui: {
            icon: 'uil-user',
            title: 'Users'
          },
          viewId: ID$1,
        },
        {
          ui: {
            icon: 'uil-university',
            title: 'White Labels'
          },
          viewId: ID,
        },
        {
          ui: {
            icon: 'uil-exclamation-triangle',
            title: 'User Errors',
            parent: 'Error Logs',
          },
          viewId: ID$d,
        },
        {
          ui: {
            icon: 'uil-exclamation-triangle',
            title: 'Anonymous Errors',
            parent: 'Error Logs',
          },
          viewId: ID$c,
        },
      ],
      aligned: 'left',
    },
    membership: membershipConfigs['system-admins'],
    space: spaces.spaces['mentornity'],
    views: [
      viewConfig$g,
      viewConfig$d,
      viewConfig$e,
      viewConfig$c,
      viewConfig$b,
      viewConfig$f,
      viewConfig$a,
      config$4(dataApi),
      config$6(dataApi),
      config$5(),
      config$3(dataApi),
      viewConfig$9,
      viewConfig$8,
      viewConfig$7,
      viewConfig$4,
      viewConfig$5,
      viewConfig$2,
      viewConfig$3,
      viewConfig$6,
      config$2(dataApi),
      config$1(dataApi),
      config(dataApi),
      viewConfig$1,
      viewConfig,
    ],
  }),
};

class UyeApiMentornity {
  constructor(endpoint, headers) {
    this.headers = headers;
    this.endpoint = endpoint;
  }
  getAppConfigOfMembership(_id) {
    return Promise.resolve(appConfigs['app-configs-system-admin']);
  }
  addAuthInterceptor(token) {
    console.log('addAuthInterceptor', token);
  }
  consentAgreement(_id) {
    return Promise.reject(utils.notImplemented('UyeApiMentornity.consentAgreement'));
  }
  getAgreement(_id) {
    return Promise.reject(utils.notImplemented('UyeApiMentornity.getAgreement'));
  }
  activateMembership(_membershipConfigId, _membershipId) {
    return Promise.reject(utils.notImplemented('UyeApiMentornity.activateMembership'));
  }
  getMembership(_membershipConfigId, _membershipId) {
    return Promise.reject(utils.notImplemented('UyeApiMentornity.getMembership'));
  }
  getMembershipsOfUser(userId) {
    return Promise.resolve({
      results: [
        membership.Membership.decode({
          _id: `system-admin-membership-for-${userId}`,
          _created: new Date(),
          _updated: new Date(),
          config: membershipConfigs['system-admins'].toObject(),
          consents: [],
          status: 'active',
          user: User.User.decode({ _id: userId }),
        })
      ]
    });
  }
  getMembershipConfig(_id) {
    return Promise.reject(utils.notImplemented('UyeApiMentornity.getMembershipConfig'));
  }
  getMembershipConfigWithName(_name) {
    return Promise.reject(utils.notImplemented('UyeApiMentornity.getMembershipConfigWithName'));
  }
  updateMembership(_membershipConfigId, _membershipId, _data) {
    return Promise.reject(utils.notImplemented('UyeApiMentornity.updateMembership'));
  }
}

exports.KimlikApiMentornity = KimlikApiMentornity;
exports.UyeApiMentornity = UyeApiMentornity;
exports.dataApiEndpoint = dataApiEndpoint;
exports.mentornityApiEndpoint = mentornityApiEndpoint;
