'use strict';

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

const index = require('./index-1141a245.js');
const dataModel = require('./data-model-9afb7f54.js');
const index$1 = require('./index-a2e99c85.js');
require('./apiBase-e4ebaf8b.js');
require('./data-transfer-field-e8417d5f.js');
require('./filter-d5040f65.js');
const instance = require('./instance-36d7564f.js');
const mentorintyBridgeApi = require('./mentorinty-bridge-api-0534712d.js');
const session = require('./session-b6f20e12.js');
const wrapperUtil = require('./wrapper-util-1d4e0a9d.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('./index-e751cab0.js');
require('./attachment-b0acc4c1.js');
require('./membership-ed8d3277.js');
require('./table-config-8b14c7d3.js');
require('./string-de672b69.js');
require('./User-e889279b.js');
require('./CalendarConfig-ee7bb722.js');
require('./UserSettings-fc04eb54.js');
require('./cookie-135bf612.js');
require('./kimlik-api-d3c479a3.js');
require('./_commonjsHelpers-206db00d.js');
require('./index-33e96540.js');
require('./i18n-49870fc9.js');
require('./i18n-5585a319.js');
require('./calendar-e4b7baeb.js');
require('./index-b776fc14.js');
require('./moment-7a3433f2.js');
require('./detail-view-config-4fe32db3.js');
require('./view-config-7972654b.js');
require('./atama-member-pairs-overview-view-config-3a953766.js');
require('./pair-config-0f8299eb.js');
require('./pair-config-c81aa77f.js');
require('./common-wrapper-util-a539b2ff.js');

const MentornityPairsOverviewWrapper = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
  }
  onAction(event) {
    const action = event.detail;
    if (action.type === 'navigation') {
      const navigateAction = action;
      if (navigateAction.direction === 'forward') {
        const navigateForwardAction = action;
        if (navigateForwardAction.name === 'open-pair-detail-view') {
          const { memberToViewRefFieldValue, pairId } = navigateForwardAction.params;
          // called when mentor/mentee clicks the "View User & Meet" button on the user card
          window.dispatchEvent(new CustomEvent('dvn.atama-pairs.open-pair-detail', {
            detail: {
              userId: memberToViewRefFieldValue,
              pairId,
            }
          }));
        }
        if (navigateForwardAction.viewId === 'pair-selection-page') {
          // called when mentee clicks the "Go to mentor selection page" on the top announcement card
          window.dispatchEvent(new CustomEvent('dvn.atama-pairs.open-pair-selection-page', {}));
        }
        if (navigateForwardAction.viewId === 'user-page') {
          // called when mentor clicks the user information from the received requests list
          this.viewUserDetailDialogActionData = navigateForwardAction;
        }
      }
    }
    if (action.name === 'send-message') {
      // called when mentor clicks the "Send Message" button from the user detail dialog
      window.dispatchEvent(new CustomEvent('dvn.atama-pairs.send-message', {
        detail: {
          user: action.params.item.user,
        }
      }));
      this.viewUserDetailDialogActionData = undefined;
    }
  }
  async componentWillLoad() {
    const { language } = this;
    const { context, headers } = session.getSessionDetails();
    this.mentornityBridgeApi = new mentorintyBridgeApi.MentornityBridgeApi(session.mentornityApiEndpoint, context, headers);
    this.apiSozluk = new index$1.SozlukApi().setLanguage(language).setContents(session.sozlukEntries);
    const mentornityApi = instance.createMentornityApiInstance(session.mentornityApiEndpoint, headers);
    const getViewConfigsResponse = await mentornityApi.getViewConfigs(context.organisationId)
      .catch(error => this.error = error);
    if (!getViewConfigsResponse)
      return;
    const viewConfigs = getViewConfigsResponse.results;
    const config = await mentornityApi.getOrganisationConfig(context.organisationId)
      .catch(error => this.error = error);
    if (!config)
      return;
    this.organisationConfig = instance.Config.decode(config);
    this.atamaMemberPairsOverviewViewConfig = wrapperUtil.getPairOverviewViewConfig(context, language, this.organisationConfig, viewConfigs);
  }
  render() {
    const { context } = session.getSessionDetails();
    const { apiSozluk, mentornityBridgeApi, organisationConfig, viewUserDetailDialogActionData } = this;
    if (!this.atamaMemberPairsOverviewViewConfig) {
      return null;
    }
    return (index.h("mentornity-root-wrapper", null, index.h("dvn-app-view-atama-member-pairs-overview-view", { apiAtama: mentornityBridgeApi, apiUye: mentornityBridgeApi, membership: dataModel.DataModel.decode({}), params: wrapperUtil.getPairOverviewParameters(context), view: this.atamaMemberPairsOverviewViewConfig }), viewUserDetailDialogActionData &&
      index.h("dvn-dialog", { raw: true, shown: true, onDismiss: () => this.viewUserDetailDialogActionData = undefined }, index.h("dvn-app-view-detail-view-card", { apiSozluk: apiSozluk, apiData: mentornityBridgeApi, id: "user-page", params: wrapperUtil.getUserDetailDialogParams(viewUserDetailDialogActionData), view: wrapperUtil.getUserDetailDialogViewConfig(context, organisationConfig) }))));
  }
};

exports.mentornity_pairs_overview_wrapper = MentornityPairsOverviewWrapper;
