import { r as registerInstance, h } from './index-b7735e0d.js';
import { D as DataModel } from './data-model-f7ccf826.js';
import { S as SozlukApi } from './index-1e9f4c53.js';
import './apiBase-d573f009.js';
import './data-transfer-field-918730a3.js';
import './filter-cbaa3d7d.js';
import { c as createMentornityApiInstance, b as Config } from './instance-7b02ef1d.js';
import { M as MentornityBridgeApi } from './mentorinty-bridge-api-78ab1153.js';
import { m as mentornityApiEndpoint } from './env-4ec3c807.js';
import { g as getSessionDetails } from './session-b16a440c.js';
import { s as sozlukEntries } from './sozluk-entries-849428da.js';
import { g as getPairOverviewViewConfig, a as getUserDetailDialogParams, b as getUserDetailDialogViewConfig, c as getPairOverviewParameters } from './wrapper-util-b6f35106.js';
import './BaseField-461b6d0c.js';
import './FieldModelGenerator-020f4a04.js';
import './reference-field-0e7cd534.js';
import './index-7b119e61.js';
import './index-403101cb.js';
import './date-ce777316.js';
import './index-1d3efe49.js';
import './index-eb14fd2d.js';
import './index-80ec23ef.js';
import './index-4c39b6a6.js';
import './index-774783ee.js';
import './attachment-32decf79.js';
import './membership-e92743d1.js';
import './table-config-0c06fb1f.js';
import './string-3065a411.js';
import './User-1ef5a482.js';
import './CalendarConfig-88c2213e.js';
import './UserSettings-27df01e6.js';
import './cookie-1686830b.js';
import './kimlikApi-0d7e6ce7.js';
import './_commonjsHelpers-27f122dd.js';
import './index-d3bd30bd.js';
import './i18n-e90027e3.js';
import './detail-view-config-59c98d8d.js';
import './view-config-dfb61752.js';
import './atama-member-pairs-overview-view-config-83ec05c4.js';
import './pair-config-f92eeeb7.js';
import './pair-config-cf56a965.js';
import './common-wrapper-util-289d199c.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 };
