'use strict';

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

const index = require('./index-1141a245.js');
const index$1 = require('./index-f41ad23a.js');
require('./apiBase-e4ebaf8b.js');
require('./data-transfer-field-e8417d5f.js');
require('./filter-d5040f65.js');
const instance = require('./instance-36d7564f.js');
const session = require('./session-b6f20e12.js');
const wrapperUtil = require('./wrapper-util-1a95b4eb.js');
require('./state-tunnel-786a62ce.js');
require('./BaseField-381327a9.js');
require('./FieldModelGenerator-1900d81a.js');
require('./reference-field-1239b0c3.js');
require('./index-2eea69a0.js');
require('./FieldGenerator-279a646b.js');
require('./date-a24d7714.js');
require('./index-0783d14f.js');
require('./index-e8e4d80b.js');
require('./index-9d3d3d15.js');
require('./index-9fd84b93.js');
require('./index-61f9621a.js');
require('./membership-ed8d3277.js');
require('./data-model-9afb7f54.js');
require('./table-config-8b14c7d3.js');
require('./string-de672b69.js');
require('./User-e889279b.js');
require('./UserSettings-fc04eb54.js');
require('./cookie-135bf612.js');
require('./kimlik-api-d3c479a3.js');
require('./_commonjsHelpers-206db00d.js');
require('./index-33e96540.js');
require('./mentorinty-bridge-api-0534712d.js');
require('./index-e751cab0.js');
require('./attachment-b0acc4c1.js');
require('./CalendarConfig-ee7bb722.js');
require('./index-a2e99c85.js');
require('./i18n-49870fc9.js');
require('./i18n-5585a319.js');
require('./calendar-e4b7baeb.js');
require('./index-b776fc14.js');
require('./moment-7a3433f2.js');
require('./ModifierTrimmer-1463d100.js');
require('./InterceptorHandler-09a1e84b.js');
require('./ValidatorLength-06e5c6f8.js');
require('./form-view-config-36569bb4.js');
require('./view-config-7972654b.js');
require('./common-wrapper-util-a539b2ff.js');
require('./models-813707d2.js');
require('./actions-d7eabd95.js');

const 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(session.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 }))));
    }
    // filter fields if additional info has been deleted
    const fieldIdsToUse = {
      // default values
      firstName: true,
      lastName: true
    };
    const oldMetadataIds = ['bio', 'skills', 'title'];
    const showOldMetaData = !this.organisationConfig.webAppConfiguration.membershipForm;
    let pairDetailViewConfig = wrapperUtil.getFormViewConfig(context, language, organisationConfig, viewConfigWrapper, user, userMetadata, userMentorship);
    if (viewConfigWrapper) {
      (viewConfigWrapper.dvnAppViewConfig.table.fields || []).forEach(usableField => {
        const oldMetadataFieldNotFound = !oldMetadataIds.includes(usableField.id);
        if (showOldMetaData || oldMetadataFieldNotFound) {
          fieldIdsToUse[usableField.id] = true;
        }
      });
      pairDetailViewConfig.ui.fields = pairDetailViewConfig.ui.fields.filter(field => fieldIdsToUse[field.fieldId]);
    }
    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;
