'use strict';

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

const index = require('./index-1ee80297.js');
const dataModel = require('./data-model-c51de090.js');
const index$1 = require('./index-b2910095.js');
require('./kimlikApi-1cd43caf.js');
require('./data-transfer-field-0ce05c1a.js');
require('./filter-d5040f65.js');
const instance = require('./instance-8904b0e4.js');
const mentorintyBridgeApi = require('./mentorinty-bridge-api-ede51458.js');
const env = require('./env-56a21d68.js');
const session = require('./session-612c0d2f.js');
const sozlukEntries = require('./sozluk-entries-34e8486b.js');
const wrapperUtil = require('./wrapper-util-3bb6f62f.js');
require('./BaseField-d019ade6.js');
require('./FieldModelGenerator-2c39c8e9.js');
require('./index-42baafa9.js');
require('./index-a77c3004.js');
require('./date-25b104f6.js');
require('./index-521d07b9.js');
require('./index-9e7c4ca0.js');
require('./index-30008542.js');
require('./attachment-3090e25e.js');
require('./membership-14c44e7c.js');
require('./membership-config-6ba394cc.js');
require('./table-config-be88299b.js');
require('./string-de672b69.js');
require('./User-286a0714.js');
require('./CalendarConfig-fed039db.js');
require('./UserSettings-016122e8.js');
require('./cookie-c4d9848a.js');
require('./_commonjsHelpers-206db00d.js');
require('./index-33e96540.js');
require('./i18n-e6beaec7.js');
require('./detail-view-config-c107e694.js');
require('./view-config-c409ff28.js');
require('./atama-member-pairs-overview-view-config-1507cd0c.js');
require('./pair-config-7be52db7.js');
require('./pair-config-aa66e586.js');
require('./common-wrapper-util-5385d126.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;
