'use strict';

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

const index = require('./index-1141a245.js');
const calendar = require('./calendar-e4b7baeb.js');
const User = require('./User-e889279b.js');
const index$1 = require('./index-a2e99c85.js');
require('./apiBase-e4ebaf8b.js');
require('./data-transfer-field-e8417d5f.js');
require('./filter-d5040f65.js');
const instance = require('./instance-36d7564f.js');
const mentorintyBridgeApi = require('./mentorinty-bridge-api-0534712d.js');
const session = require('./session-b6f20e12.js');
const wrapperUtil = require('./wrapper-util-fc8865e9.js');
require('./index-b776fc14.js');
require('./_commonjsHelpers-206db00d.js');
require('./moment-7a3433f2.js');
require('./data-model-9afb7f54.js');
require('./BaseField-381327a9.js');
require('./FieldModelGenerator-1900d81a.js');
require('./reference-field-1239b0c3.js');
require('./index-2eea69a0.js');
require('./FieldGenerator-279a646b.js');
require('./date-a24d7714.js');
require('./index-0783d14f.js');
require('./index-e8e4d80b.js');
require('./index-9d3d3d15.js');
require('./index-9fd84b93.js');
require('./index-61f9621a.js');
require('./index-e751cab0.js');
require('./attachment-b0acc4c1.js');
require('./membership-ed8d3277.js');
require('./table-config-8b14c7d3.js');
require('./string-de672b69.js');
require('./CalendarConfig-ee7bb722.js');
require('./UserSettings-fc04eb54.js');
require('./cookie-135bf612.js');
require('./kimlik-api-d3c479a3.js');
require('./index-33e96540.js');
require('./i18n-49870fc9.js');
require('./i18n-5585a319.js');
require('./card-list-view-config-61d6ecea.js');
require('./view-config-7972654b.js');
require('./detail-view-config-4fe32db3.js');
require('./takvim-available-time-picker-view-config-816b6faf.js');
require('./common-wrapper-util-a539b2ff.js');
require('./models-8b357ee7.js');

const MentornityUserCardListWrapper = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.weekStartDay = 'monday';
  }
  async componentWillLoad() {
    const { isZoomAuthenticated, language, timeFormat, dateFormat, timeZone, viewedUserRole, weekStartDay, } = this;
    // set user's locale and time zone
    calendar.CalendarUtils.setTimeFormat(timeFormat);
    calendar.CalendarUtils.setTimeZone(timeZone);
    calendar.CalendarUtils.setDateFormat(dateFormat);
    switch (language) {
      case 'pt-br':
        calendar.CalendarUtils.setLocale(language, session.sozlukCalendarEntryPtBr, weekStartDay);
        break;
      case 'tr':
        calendar.CalendarUtils.setLocale(language, session.sozlukCalendarEntryTr, weekStartDay);
        break;
      default:
        calendar.CalendarUtils.setLocale(language, session.sozlukCalendarEntryEn, weekStartDay);
        break;
    }
    this.apiSozluk = new index$1.SozlukApi().setLanguage(language).setContents(session.sozlukEntries);
    const { context, headers } = session.getSessionDetails(this.groupId);
    this.mentornityCookieContext = context;
    this.userSettings = session.getUserSettings(timeFormat, dateFormat, timeZone, language, isZoomAuthenticated, weekStartDay);
    this.mentornityBridgeApi = new mentorintyBridgeApi.MentornityBridgeApi(session.mentornityApiEndpoint, context, headers);
    const mentornityApi = instance.createMentornityApiInstance(session.mentornityApiEndpoint, headers);
    const user = await mentornityApi.get('users', context.userId)
      .catch(error => this.error = error);
    if (!user)
      return;
    this.user = 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 = session.generateMembershipForRole('group');
    }
    else {
      this.membership = session.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 = instance.Config.decode(config);
    this.organisationConfig = organisationConfig;
    this.mentornityBridgeApi.organisationConfig = organisationConfig;
    this.userCardListViewConfig = wrapperUtil.getUserCardListViewConfig(context, language, organisationConfig, viewedUserRole, {
      mentornityBridgeApi: this.mentornityBridgeApi,
      apiSozluk: this.apiSozluk,
      guestToPassToAvailableTimePickerAsCurrentUser: this.guestToPassToAvailableTimePickerAsCurrentUser,
      userSettings: this.userSettings,
      membership: this.membership,
    });
    this.userDetailDialogViewConfig = wrapperUtil.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 (index.h("div", { class: "d-flex justify-content-center pt-3" }, index.h("dvn-progress", { indefinite: true })));
    }
    return (index.h(index.Host, { style: { display: 'flex', flexDirection: 'column', height: '100%', overflow: 'hidden' } }, index.h("mentornity-root-wrapper", null, index.h("div", { style: { display: 'flex', overflow: 'hidden', flexDirection: 'column' } }, this.alertMessage &&
      index.h("dvn-alert", { tint: "warning", message: this.alertMessage, extraClass: "mt-3 ml-3 mr-3" }, index.h("dvn-card-footer", { slot: "footer", "align-right": true }, index.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))), index.h("dvn-app-view-list-view-card", { apiData: mentornityBridgeApi, apiSozluk: apiSozluk, view: userCardListViewConfig })), userToViewDetails &&
      index.h("dvn-dialog", { raw: true, shown: true, onDismiss: () => this.userToViewDetails = undefined }, index.h("dvn-app-view-detail-view-card", { apiData: mentornityBridgeApi, apiSozluk: apiSozluk, id: "user-page", params: {
          itemId: userToViewDetails._id,
        }, view: userDetailDialogViewConfig })))));
  }
  get el() { return index.getElement(this); }
};

exports.mentornity_user_card_list_wrapper = MentornityUserCardListWrapper;
