import { r as registerInstance, h } from './index-ecdfb761.js';
import { i as injectNotifier } from './index-1e6a7311.js';
import './apiBase-6015f41f.js';
import './data-transfer-field-2f305919.js';
import './filter-cbaa3d7d.js';
import { g as getSessionDetails, c as createMentornityApiInstance, m as mentornityApiEndpoint, h as MentornityViewConfigViewName } from './session-2a491341.js';
import { a as getFormViewConfig, b as getFormParameters } from './wrapper-util-2b15cdf3.js';
import './state-tunnel-04c0b67a.js';
import './BaseField-0b01dc2c.js';
import './membership-b6639471.js';
import './data-model-88af49fc.js';
import './table-config-d73a72ab.js';
import './FieldModelGenerator-378c8613.js';
import './reference-field-a5b414d1.js';
import './index-61dcd269.js';
import './FieldGenerator-3ae403b2.js';
import './date-1bc489bd.js';
import './index-4e451db4.js';
import './index-23baeeef.js';
import './index-09efdc01.js';
import './index-150b6a59.js';
import './string-3065a411.js';
import './User-72c4643a.js';
import './UserSettings-7e4170a7.js';
import './cookie-5d9f5819.js';
import './kimlik-api-fddeac81.js';
import './_commonjsHelpers-27f122dd.js';
import './index-d3bd30bd.js';
import './mentorinty-bridge-api-5ca2d652.js';
import './index-e66e8eca.js';
import './attachment-961dd228.js';
import './CalendarConfig-412d1b0f.js';
import './index-3bf9b308.js';
import './sozluk-entries-1e8f5234.js';
import './i18n-09a07b97.js';
import './i18n-0e757ca5.js';
import './calendar-470c802a.js';
import './index-a3ca021c.js';
import './moment-65eca6b3.js';
import './ModifierTrimmer-2f77f917.js';
import './InterceptorHandler-6474bcf4.js';
import './ValidatorLength-f56a7c14.js';
import './form-view-config-e5a5ced8.js';
import './view-config-1ed8c59f.js';
import './common-wrapper-util-e4afa19b.js';
import './models-f0bc20c6.js';
import './actions-b9a0f808.js';

const MentornityMembershipSettingsWrapper = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.isViewConfigWrapperLoaded = false;
  }
  onInvalidation(event) {
    this.notifier.showCustomNotification(event.detail.notification);
  }
  ;
  componentWillLoad() {
    const { context: { organisationId, role, userId }, headers } = getSessionDetails();
    const mentornityApi = createMentornityApiInstance(mentornityApiEndpoint, headers);
    mentornityApi.getOrganisationConfig(organisationId).then((response) => {
      this.organisationConfig = response;
    });
    const viewName = role === 'mentor'
      ? MentornityViewConfigViewName.MentorInfoForm
      : 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 } = getSessionDetails();
    if (!isViewConfigWrapperLoaded || !organisationConfig || !user || !userMetadata || (context.role === 'mentor' && !userMentorship)) {
      return (h("mentornity-root-wrapper", null, h("div", { class: "d-flex justify-content-center pt-3" }, 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 = 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 (h("mentornity-root-wrapper", null, h("dvn-card", null, h("dvn-app-view-form-view", { params: getFormParameters(context, organisationConfig, user, userMetadata, userMentorship), view: pairDetailViewConfig }))));
  }
};
injectNotifier(MentornityMembershipSettingsWrapper);

export { MentornityMembershipSettingsWrapper as mentornity_membership_settings_wrapper };
