'use strict';

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

const index = require('./index-ce58ddc5.js');
const dataModel = require('./data-model-9afb7f54.js');
const index$1 = require('./index-b2910095.js');
require('./apiBase-b14a8285.js');
require('./data-transfer-field-0ce05c1a.js');
require('./filter-d5040f65.js');
const instance = require('./instance-fba77445.js');
const mentorintyBridgeApi = require('./mentorinty-bridge-api-616ff4b9.js');
const env = require('./env-56a21d68.js');
const session = require('./session-fe19e012.js');
const sozlukEntries = require('./sozluk-entries-415b953f.js');
const wrapperUtil = require('./wrapper-util-3e4d6318.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('./index-fa185e3b.js');
require('./attachment-3090e25e.js');
require('./membership-310dd68e.js');
require('./table-config-73a193be.js');
require('./string-de672b69.js');
require('./User-e15e0b6d.js');
require('./CalendarConfig-7f8ef631.js');
require('./UserSettings-fc04eb54.js');
require('./cookie-ea977378.js');
require('./kimlikApi-f4f62100.js');
require('./_commonjsHelpers-206db00d.js');
require('./index-33e96540.js');
require('./i18n-1b762664.js');
require('./detail-view-config-ba51db6c.js');
require('./view-config-1c8cc7cb.js');
require('./atama-member-pairs-overview-view-config-7d87e3ec.js');
require('./pair-config-6e44fea9.js');
require('./pair-config-278a2924.js');
require('./common-wrapper-util-f504304b.js');

let 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(env.mentornityApiEndpoint, context, headers);
    this.apiSozluk = new index$1.SozlukApi().setLanguage(language).setContents(sozlukEntries.sozlukEntries);
    const mentornityApi = instance.createMentornityApiInstance(env.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;
