'use strict';

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

const index = require('./index-1141a245.js');
const calendar = require('./calendar-e4b7baeb.js');
const User = require('./User-dbfbd45e.js');
const index$1 = require('./index-a2e99c85.js');
require('./apiBase-6c66ff1b.js');
require('./data-transfer-field-e8417d5f.js');
require('./filter-d5040f65.js');
const session = require('./session-f588baa3.js');
const mentorintyBridgeApi = require('./mentorinty-bridge-api-b1eaa56d.js');
const sozlukEntries = require('./sozluk-entries-3b9686e7.js');
const wrapperUtil = require('./wrapper-util-9c556481.js');
require('./index-b776fc14.js');
require('./_commonjsHelpers-206db00d.js');
require('./moment-7a3433f2.js');
require('./data-model-01c368bc.js');
require('./BaseField-381327a9.js');
require('./membership-e87e02ed.js');
require('./table-config-969d3038.js');
require('./FieldModelGenerator-d61f01d4.js');
require('./reference-field-1239b0c3.js');
require('./index-2eea69a0.js');
require('./FieldGenerator-279a646b.js');
require('./date-a24d7714.js');
require('./index-0783d14f.js');
require('./index-9d3d3d15.js');
require('./index-9fd84b93.js');
require('./index-61f9621a.js');
require('./string-de672b69.js');
require('./UserSettings-2a2399b1.js');
require('./cookie-e64bc800.js');
require('./kimlik-api-663f4884.js');
require('./index-33e96540.js');
require('./index-b7855ed6.js');
require('./attachment-a0cdf203.js');
require('./CalendarConfig-998f742e.js');
require('./i18n-0bcf144d.js');
require('./i18n-77d45414.js');
require('./card-list-view-config-ba20191c.js');
require('./view-config-52c16db0.js');
require('./detail-view-config-7bcb0034.js');
require('./takvim-available-time-picker-view-config-6bf1a5d8.js');
require('./common-wrapper-util-95591ac2.js');
require('./models-8b357ee7.js');

const MentornityUserCardListWrapper = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.weekStartDay = 'monday';
  }
  async componentWillLoad() {
    const { isZoomAuthenticated, isGoogleAuthenticated, isMicrosoftBusinessAuthenticated, 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, sozlukEntries.sozlukCalendarEntryPtBr, weekStartDay);
        break;
      case 'tr':
        calendar.CalendarUtils.setLocale(language, sozlukEntries.sozlukCalendarEntryTr, weekStartDay);
        break;
      default:
        calendar.CalendarUtils.setLocale(language, sozlukEntries.sozlukCalendarEntryEn, weekStartDay);
        break;
    }
    this.apiSozluk = new index$1.SozlukApi().setLanguage(language).setContents(sozlukEntries.sozlukEntries);
    const { context, headers } = session.getSessionDetails(this.groupId);
    this.mentornityCookieContext = context;
    this.userSettings = session.getUserSettings(timeFormat, dateFormat, timeZone, language, isZoomAuthenticated, isGoogleAuthenticated, isMicrosoftBusinessAuthenticated, weekStartDay);
    this.mentornityBridgeApi = new mentorintyBridgeApi.MentornityBridgeApi(session.mentornityApiEndpoint, context, headers);
    const mentornityApi = session.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 = session.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 'send-message':
        window.dispatchEvent(new CustomEvent('dvn.mentornity-user-card-list-wrapper.send-message', {
          detail: {
            user: action.params.item.user,
          }
        }));
        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;
