import { r as registerInstance, h, H as Host, g as getElement } from './index-ecdfb761.js';
import { C as CalendarUtils } from './calendar-470c802a.js';
import { U as User } from './User-9f1f4513.js';
import { S as SozlukApi } from './index-3bf9b308.js';
import './apiBase-648a161d.js';
import './data-transfer-field-2f305919.js';
import './filter-cbaa3d7d.js';
import { c as createMentornityApiInstance, b as Config } from './instance-db63ecb7.js';
import { M as MentornityBridgeApi } from './mentorinty-bridge-api-f70621dd.js';
import { h as sozlukCalendarEntryEn, i as sozlukCalendarEntryTr, j as sozlukCalendarEntryPtBr, s as sozlukEntries, g as getSessionDetails, k as getUserSettings, a as mentornityApiEndpoint, c as generateMembershipForRole } from './session-a602596d.js';
import { a as getUserCardListViewConfig, b as getUserDetailDialogViewConfig } from './wrapper-util-2baa8a90.js';
import './index-a3ca021c.js';
import './_commonjsHelpers-27f122dd.js';
import './moment-65eca6b3.js';
import './data-model-f7ccf826.js';
import './BaseField-0b01dc2c.js';
import './FieldModelGenerator-03c7516c.js';
import './reference-field-a5b414d1.js';
import './index-61dcd269.js';
import './FieldGenerator-3ae403b2.js';
import './date-1bc489bd.js';
import './index-4e451db4.js';
import './index-32d8b974.js';
import './index-23baeeef.js';
import './index-09efdc01.js';
import './index-150b6a59.js';
import './index-5f14b4fc.js';
import './attachment-d13ad547.js';
import './membership-24db029a.js';
import './table-config-3820fb34.js';
import './string-3065a411.js';
import './CalendarConfig-f8d4a70d.js';
import './UserSettings-27df01e6.js';
import './cookie-9f22e0fb.js';
import './kimlik-api-66e341bd.js';
import './index-d3bd30bd.js';
import './i18n-4dcb85fe.js';
import './i18n-73c2e20d.js';
import './card-list-view-config-56edd30b.js';
import './view-config-2fc2ba10.js';
import './detail-view-config-47244869.js';
import './takvim-available-time-picker-view-config-051fa55b.js';
import './common-wrapper-util-62bbacf2.js';
import './models-3a85e626.js';

const MentornityUserCardListWrapper = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.weekStartDay = 'monday';
  }
  async componentWillLoad() {
    const { isZoomAuthenticated, language, timeFormat, dateFormat, timeZone, viewedUserRole, weekStartDay, } = this;
    // set user's locale and time zone
    CalendarUtils.setTimeFormat(timeFormat);
    CalendarUtils.setTimeZone(timeZone);
    CalendarUtils.setDateFormat(dateFormat);
    switch (language) {
      case 'pt-br':
        CalendarUtils.setLocale(language, sozlukCalendarEntryPtBr, weekStartDay);
        break;
      case 'tr':
        CalendarUtils.setLocale(language, sozlukCalendarEntryTr, weekStartDay);
        break;
      default:
        CalendarUtils.setLocale(language, sozlukCalendarEntryEn, weekStartDay);
        break;
    }
    this.apiSozluk = new SozlukApi().setLanguage(language).setContents(sozlukEntries);
    const { context, headers } = getSessionDetails(this.groupId);
    this.mentornityCookieContext = context;
    this.userSettings = getUserSettings(timeFormat, dateFormat, timeZone, language, isZoomAuthenticated, weekStartDay);
    this.mentornityBridgeApi = new MentornityBridgeApi(mentornityApiEndpoint, context, headers);
    const mentornityApi = createMentornityApiInstance(mentornityApiEndpoint, headers);
    const user = await mentornityApi.get('users', context.userId)
      .catch(error => this.error = error);
    if (!user)
      return;
    this.user = User.decode(user);
    const config = await mentornityApi.getOrganisationConfig(context.organisationId)
      .catch(error => this.error = error);
    if (!config)
      return;
    if (context.role === 'mentee' && config.menteeType === 'group') {
      this.membership = generateMembershipForRole('group');
    }
    else {
      this.membership = generateMembershipForRole(context.role);
    }
    this.guestToPassToAvailableTimePickerAsCurrentUser = this.user;
    if (context.role === 'mentee' && config.menteeType === 'group') {
      // fetch the group of the mentee and set as the guest instead of the mentee
      if (context.groupId) {
        const group = await mentornityApi.getGroup(context.groupId).catch(error => this.error = error);
        if (group) {
          this.guestToPassToAvailableTimePickerAsCurrentUser = Object.assign(Object.assign({}, group), { name: group.title, initials: group.title[0] });
        }
      }
      else {
        this.guestToPassToAvailableTimePickerAsCurrentUser = undefined;
      }
    }
    const organisationConfig = Config.decode(config);
    this.organisationConfig = organisationConfig;
    this.mentornityBridgeApi.organisationConfig = organisationConfig;
    this.userCardListViewConfig = getUserCardListViewConfig(context, language, organisationConfig, viewedUserRole, {
      mentornityBridgeApi: this.mentornityBridgeApi,
      apiSozluk: this.apiSozluk,
      guestToPassToAvailableTimePickerAsCurrentUser: this.guestToPassToAvailableTimePickerAsCurrentUser,
      userSettings: this.userSettings,
      membership: this.membership,
    });
    this.userDetailDialogViewConfig = getUserDetailDialogViewConfig(context, language, organisationConfig, viewedUserRole);
  }
  componentDidRender() {
    var _a, _b;
    (_b = (_a = this.el.querySelector(`dvn-app-view-list-view-card`)) === null || _a === void 0 ? void 0 : _a.retainPosition) === null || _b === void 0 ? void 0 : _b.call(_a);
  }
  onAction(event) {
    const action = event.detail;
    switch (action.name) {
      case 'view-details':
        this.userToViewDetails = action.params.item;
        break;
      case 'go-to-profile-page':
        // dispatch event for Mentornity web-client to handle the action
        window.dispatchEvent(new CustomEvent('dvn.mentornity-user-card-list-wrapper.open-profile-page', {
          detail: {
            user: action.params.item,
          }
        }));
        break;
      case 'open-meeting-detail-after-creation':
        // dispatch event for Mentornity web-client to handle the action
        window.dispatchEvent(new CustomEvent('dvn.mentornity-user-card-list-wrapper.open-meeting-page', {
          detail: {
            meetingId: action.params.meetingId,
          }
        }));
        break;
    }
  }
  render() {
    const { apiSozluk, mentornityBridgeApi, userCardListViewConfig, userToViewDetails, userDetailDialogViewConfig, } = this;
    if (!userCardListViewConfig) {
      return (h("div", { class: "d-flex justify-content-center pt-3" }, h("dvn-progress", { indefinite: true })));
    }
    return (h(Host, { style: { display: 'flex', flexDirection: 'column', height: '100%', overflow: 'hidden' } }, h("mentornity-root-wrapper", null, h("div", { style: { display: 'flex', overflow: 'hidden', flexDirection: 'column' } }, this.alertMessage &&
      h("dvn-alert", { tint: "warning", message: this.alertMessage, extraClass: "mt-3 ml-3 mr-3" }, h("dvn-card-footer", { slot: "footer", "align-right": true }, h("dvn-button", { leaned: true, tint: "secondary", view: "flat", onClick: () => window.dispatchEvent(new CustomEvent('dvn.mentornity-user-card-list-wrapper.alert-message-click')) }, this.alertActionLabel))), h("dvn-app-view-list-view-card", { apiData: mentornityBridgeApi, apiSozluk: apiSozluk, view: userCardListViewConfig })), userToViewDetails &&
      h("dvn-dialog", { raw: true, shown: true, onDismiss: () => this.userToViewDetails = undefined }, h("dvn-app-view-detail-view-card", { apiData: mentornityBridgeApi, apiSozluk: apiSozluk, id: "user-page", params: {
          itemId: userToViewDetails._id,
        }, view: userDetailDialogViewConfig })))));
  }
  get el() { return getElement(this); }
};

export { MentornityUserCardListWrapper as mentornity_user_card_list_wrapper };
