'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index = require('./index-ce58ddc5.js');
const index$1 = require('./index-407b6960.js');
require('./apiBase-b14a8285.js');
require('./data-transfer-field-0ce05c1a.js');
require('./filter-d5040f65.js');
const instance = require('./instance-fba77445.js');
const env = require('./env-56a21d68.js');
const session = require('./session-fe19e012.js');
const wrapperUtil = require('./wrapper-util-ec16eb28.js');
require('./state-tunnel-786a62ce.js');
require('./BaseField-d019ade6.js');
require('./FieldModelGenerator-1af8e5c3.js');
require('./reference-field-dda66f2e.js');
require('./index-f92537c9.js');
require('./index-7e3bc620.js');
require('./date-25b104f6.js');
require('./index-9ea6c7b1.js');
require('./index-93271b8c.js');
require('./index-29b7cb16.js');
require('./index-792d710c.js');
require('./membership-310dd68e.js');
require('./data-model-9afb7f54.js');
require('./table-config-73a193be.js');
require('./string-de672b69.js');
require('./User-e15e0b6d.js');
require('./UserSettings-fc04eb54.js');
require('./cookie-ea977378.js');
require('./kimlikApi-f4f62100.js');
require('./_commonjsHelpers-206db00d.js');
require('./index-33e96540.js');
require('./ModifierTrimmer-1463d100.js');
require('./InterceptorHandler-09a1e84b.js');
require('./ValidatorLength-06e5c6f8.js');
require('./form-view-config-b408970d.js');
require('./view-config-1c8cc7cb.js');
require('./mentorinty-bridge-api-616ff4b9.js');
require('./index-fa185e3b.js');
require('./attachment-3090e25e.js');
require('./CalendarConfig-7f8ef631.js');
require('./common-wrapper-util-f504304b.js');
require('./models-813707d2.js');
require('./actions-d7eabd95.js');

let MentornityMembershipSettingsWrapper = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.isViewConfigWrapperLoaded = false;
  }
  onInvalidation(event) {
    this.notifier.showCustomNotification(event.detail.notification);
  }
  ;
  componentWillLoad() {
    const { context: { organisationId, role, userId }, headers } = session.getSessionDetails();
    const mentornityApi = instance.createMentornityApiInstance(env.mentornityApiEndpoint, headers);
    mentornityApi.getOrganisationConfig(organisationId).then((response) => {
      this.organisationConfig = response;
    });
    const viewName = role === 'mentor'
      ? instance.MentornityViewConfigViewName.MentorInfoForm
      : instance.MentornityViewConfigViewName.MenteeInfoForm;
    mentornityApi.getViewConfig(organisationId, viewName)
      .then(viewConfigWrapper => {
      this.viewConfigWrapper = viewConfigWrapper;
    }).finally(() => this.isViewConfigWrapperLoaded = true);
    mentornityApi.get('users', userId).then((response) => {
      this.user = response;
    });
    mentornityApi
      .getMetadataOfUser(organisationId, role === 'mentor' ? 'mentors' : 'mentees', userId)
      .then((response) => {
      this.userMetadata = response;
    });
    if (role === 'mentor') {
      mentornityApi
        .getMentorshipOfUser(organisationId, userId)
        .then((response) => {
        this.userMentorship = response;
      });
    }
  }
  render() {
    const { isViewConfigWrapperLoaded, language, organisationConfig, user, userMentorship, userMetadata, viewConfigWrapper } = this;
    const { context } = session.getSessionDetails();
    if (!isViewConfigWrapperLoaded || !organisationConfig || !user || !userMetadata || (context.role === 'mentor' && !userMentorship)) {
      return (index.h("mentornity-root-wrapper", null, index.h("div", { class: "d-flex justify-content-center pt-3" }, index.h("dvn-progress", { indefinite: true }))));
    }
    const pairDetailViewConfig = wrapperUtil.getFormViewConfig(context, language, organisationConfig, viewConfigWrapper, user, userMetadata, userMentorship);
    return (index.h("mentornity-root-wrapper", null, index.h("dvn-card", null, index.h("dvn-app-view-form-view", { params: wrapperUtil.getFormParameters(context, organisationConfig, user, userMetadata, userMentorship), view: pairDetailViewConfig }))));
  }
};
index$1.injectNotifier(MentornityMembershipSettingsWrapper);

exports.mentornity_membership_settings_wrapper = MentornityMembershipSettingsWrapper;
