import { r as registerInstance, h } from './index-ecdfb761.js';
import { D as DataModel } from './data-model-88af49fc.js';
import { S as SozlukApi } from './index-3bf9b308.js';
import './apiBase-6015f41f.js';
import './data-transfer-field-2f305919.js';
import './filter-cbaa3d7d.js';
import { g as getSessionDetails, m as mentornityApiEndpoint, c as createMentornityApiInstance, e as Config } from './session-2a491341.js';
import { M as MentornityBridgeApi } from './mentorinty-bridge-api-5ca2d652.js';
import { s as sozlukEntries } from './sozluk-entries-1e8f5234.js';
import { g as getPairOverviewViewConfig, a as getUserDetailDialogParams, b as getUserDetailDialogViewConfig, c as getPairOverviewParameters } from './wrapper-util-9b6b4574.js';
import './BaseField-0b01dc2c.js';
import './membership-b6639471.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 './calendar-470c802a.js';
import './index-a3ca021c.js';
import './moment-65eca6b3.js';
import './index-e66e8eca.js';
import './attachment-961dd228.js';
import './CalendarConfig-412d1b0f.js';
import './i18n-09a07b97.js';
import './i18n-0e757ca5.js';
import './detail-view-config-23af2b0d.js';
import './view-config-1ed8c59f.js';
import './atama-member-pairs-overview-view-config-ae8ec43d.js';
import './pair-config-a31d66bf.js';
import './pair-config-13b5a7c1.js';
import './common-wrapper-util-e4afa19b.js';

const MentornityPairsOverviewWrapper = class {
  constructor(hostRef) {
    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 } = getSessionDetails();
    this.mentornityBridgeApi = new MentornityBridgeApi(mentornityApiEndpoint, context, headers);
    this.apiSozluk = new SozlukApi().setLanguage(language).setContents(sozlukEntries);
    const mentornityApi = createMentornityApiInstance(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 = Config.decode(config);
    this.atamaMemberPairsOverviewViewConfig = getPairOverviewViewConfig(context, language, this.organisationConfig, viewConfigs);
  }
  render() {
    const { context } = getSessionDetails();
    const { apiSozluk, mentornityBridgeApi, organisationConfig, viewUserDetailDialogActionData } = this;
    if (!this.atamaMemberPairsOverviewViewConfig) {
      return null;
    }
    return (h("mentornity-root-wrapper", null, h("dvn-app-view-atama-member-pairs-overview-view", { apiAtama: mentornityBridgeApi, apiUye: mentornityBridgeApi, membership: DataModel.decode({}), params: getPairOverviewParameters(context), view: this.atamaMemberPairsOverviewViewConfig }), viewUserDetailDialogActionData &&
      h("dvn-dialog", { raw: true, shown: true, onDismiss: () => this.viewUserDetailDialogActionData = undefined }, h("dvn-app-view-detail-view-card", { apiSozluk: apiSozluk, apiData: mentornityBridgeApi, id: "user-page", params: getUserDetailDialogParams(viewUserDetailDialogActionData), view: getUserDetailDialogViewConfig(context, organisationConfig) }))));
  }
};

export { MentornityPairsOverviewWrapper as mentornity_pairs_overview_wrapper };
