import { r as registerInstance, h } from './index-102043e0.js';
import { D as DataModel } from './data-model-f5160369.js';
import { S as SozlukApi } from './index-1e9f4c53.js';
import './kimlikApi-ac700c81.js';
import './data-transfer-field-918730a3.js';
import './filter-cbaa3d7d.js';
import { c as createMentornityApiInstance, b as Config } from './instance-fe40f49f.js';
import { M as MentornityBridgeApi } from './mentorinty-bridge-api-fc8ad2d8.js';
import { m as mentornityApiEndpoint } from './env-4ec3c807.js';
import { g as getSessionDetails } from './session-4127c2a1.js';
import { s as sozlukEntries } from './sozluk-entries-e1fd9179.js';
import { g as getPairOverviewViewConfig, a as getUserDetailDialogParams, b as getUserDetailDialogViewConfig, c as getPairOverviewParameters } from './wrapper-util-444380d8.js';
import './BaseField-461b6d0c.js';
import './FieldModelGenerator-ee438a53.js';
import './index-ef734a5e.js';
import './index-336ef773.js';
import './date-ce777316.js';
import './index-0e8b9ea2.js';
import './index-c3eacf05.js';
import './index-a1675f50.js';
import './attachment-32decf79.js';
import './membership-821de3c5.js';
import './membership-config-68ed7772.js';
import './table-config-720f8ea0.js';
import './string-3065a411.js';
import './User-d2ee8b71.js';
import './CalendarConfig-cc1e3a80.js';
import './UserSettings-7b80b841.js';
import './cookie-647f9dc7.js';
import './_commonjsHelpers-27f122dd.js';
import './index-d3bd30bd.js';
import './i18n-2b616f25.js';
import './detail-view-config-e2344d5e.js';
import './view-config-efdeed6d.js';
import './atama-member-pairs-overview-view-config-7a52c297.js';
import './pair-config-c376904c.js';
import './pair-config-01882539.js';
import './common-wrapper-util-f1abefff.js';

let 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 };
