'use strict';

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

const index$1 = require('./index-1ee80297.js');
const calendar = require('./calendar-e830b67f.js');
const index$2 = require('./index-b2910095.js');
require('./kimlikApi-1cd43caf.js');
require('./data-transfer-field-0ce05c1a.js');
require('./filter-d5040f65.js');
const instance = require('./instance-8904b0e4.js');
const mentorintyBridgeApi = require('./mentorinty-bridge-api-ede51458.js');
const env = require('./env-56a21d68.js');
const session = require('./session-612c0d2f.js');
const sozlukEntries = require('./sozluk-entries-34e8486b.js');
const models = require('./models-19fd9c92.js');
const compositeViewLinearConfig = require('./composite-view-linear-config-043800db.js');
require('./index-30008542.js');
const index = require('./index-a77c3004.js');
const actions = require('./actions-d7eabd95.js');
const appConfig = require('./app-config-e62f5843.js');
const detailViewConfig = require('./detail-view-config-c107e694.js');
const tableConfig = require('./table-config-be88299b.js');
const viewConfig = require('./view-config-c409ff28.js');
const takvimAvailableTimePickerViewConfig = require('./takvim-available-time-picker-view-config-5b4dbdd1.js');
const commonWrapperUtil = require('./common-wrapper-util-5385d126.js');
const attachment = require('./attachment-3090e25e.js');
require('./index-1f95aafc.js');
require('./_commonjsHelpers-206db00d.js');
require('./moment-d48a0164.js');
require('./BaseField-d019ade6.js');
require('./FieldModelGenerator-2c39c8e9.js');
require('./index-42baafa9.js');
require('./date-25b104f6.js');
require('./index-521d07b9.js');
require('./index-9e7c4ca0.js');
require('./data-model-c51de090.js');
require('./membership-14c44e7c.js');
require('./membership-config-6ba394cc.js');
require('./string-de672b69.js');
require('./User-286a0714.js');
require('./CalendarConfig-fed039db.js');
require('./UserSettings-016122e8.js');
require('./cookie-c4d9848a.js');
require('./index-33e96540.js');
require('./i18n-e6beaec7.js');

function getAppConfig(mentornityCookieContext, organisationConfig, language, viewedUserRole) {
  const showMessageButton = viewedUserRole === 'mentor'
    ? [
      instance.InfoVisibility.allMentors,
      instance.InfoVisibility.everyone,
    ].includes(organisationConfig.conversationPermissions.mentee)
    : [
      instance.InfoVisibility.allMentees,
      instance.InfoVisibility.everyone,
    ].includes(organisationConfig.conversationPermissions.mentor);
  const actions$1 = [
    {
      ui: {
        componentTag: 'mentornity-follow-button',
        name: 'toggle-follow',
      },
      data: {
        language,
        mentornityCookieContext,
      }
    },
  ];
  if (showMessageButton) {
    actions$1.push({
      ui: {
        label: mentorintyBridgeApi.getEmbeddedTranslation(language, 'sendMessage'),
        name: 'send-message',
        view: 'flat'
      }
    });
  }
  return appConfig.AppConfig.decode({
    views: [
      detailViewConfig.DetailViewConfig.decode({
        _id: 'user-detail-page-summary-card-view',
        type: viewConfig.AppViewType.DetailViewCard,
        table: tableConfig.TableConfig.decode({
          fields: [
            new index.TextField('name', ''),
            new index.TextField('initials', ''),
            new attachment.AttachmentField('imageUrl', ''),
          ],
          roleName: viewedUserRole,
          name: `${viewedUserRole}-detail-view`,
        }),
        ui: {
          cardConfig: {
            header: {
              title: {
                fieldId: 'name',
                position: models.TitlePosition.RightOfImage,
              },
              image: {
                fieldId: 'imageUrl',
                placeholderFieldId: 'initials',
                position: models.ImagePosition.BottomLeft,
              },
              cover: {
                // placeholder: 'https://thumbs.dreamstime.com/z/books-wooden-desk-table-abstract-background-education-copy-space-back-to-school-184388515.jpg',
                size: 88,
              },
            },
            footer: {
              actions: actions$1,
            }
          }
        },
      }),
      getDetailViewUIConfig(mentornityCookieContext, language, organisationConfig, viewedUserRole),
      takvimAvailableTimePickerViewConfig.TakvimAvailableTimePickerViewConfig.decode({
        _id: 'user-detail-page-available-time-picker-view',
        i18nEntryId: 'user-detail-page-available-time-picker-view',
        type: viewConfig.AppViewType.TakvimAvailableTimePickerView,
        table: mentorintyBridgeApi.generateCalendarConfig(organisationConfig),
        events: {
          success: [
            new actions.InvalidationAction('user-detail-page-available-time-picker-view', 'user-detail-page-meeting-list-view'),
          ]
        },
        successNavigationAction: {
          type: 'navigation',
          direction: 'forward',
          name: 'open-meeting-detail-after-creation',
          params: {
            conversionConfig: {
              'item._id': 'meetingId',
            }
          }
        },
      }),
      takvimAvailableTimePickerViewConfig.TakvimAvailableTimePickerViewConfig.decode({
        _id: 'user-detail-page-meeting-list-view',
        i18nEntryId: 'user-detail-page-meeting-list-view',
        type: viewConfig.AppViewType.TakvimMeetingListViewTable,
        table: mentorintyBridgeApi.generateCalendarConfig(organisationConfig),
      }),
    ]
  });
}
function getDetailViewUIConfig(mentornityCookieContext, language, config, viewedUserRole) {
  if (!config) {
    return null;
  }
  const fields = commonWrapperUtil.getMembershipFields(language, config, viewedUserRole, mentornityCookieContext.role);
  const summaryCardFields = commonWrapperUtil.getUserDetailViewFieldConfigs(language, config, viewedUserRole, mentornityCookieContext.role, true, 3);
  const detailCardFields = commonWrapperUtil.getUserDetailViewFieldConfigs(language, config, viewedUserRole, mentornityCookieContext.role, true, 0);
  return detailViewConfig.DetailViewConfig.decode({
    _id: 'user-detail-page-info-view',
    i18nEntryId: 'user-detail-page-info-view',
    type: viewConfig.AppViewType.DetailViewCard,
    table: tableConfig.TableConfig.decode({
      fields,
      roleName: viewedUserRole,
      name: `${viewedUserRole}-detail-view`,
    }),
    ui: {
      summaryCardConfig: {
        body: {
          fields: summaryCardFields,
        }
      },
      cardConfig: {
        body: {
          fields: detailCardFields,
        }
      },
    },
  });
}
function getCompositeViewUIConfig(language, userId, groupId, viewedUserRole) {
  return compositeViewLinearConfig.CompositeViewLinearConfig.decode({
    _id: 'mentornity-user-detail-page',
    table: {
      name: viewedUserRole === 'mentee' ? 'mentees' : 'mentors',
    },
    type: viewConfig.AppViewType.CompositeViewLinear,
    params: undefined,
    ui: {
      layout: 'vertical',
      views: [
        {
          viewId: 'user-detail-page-summary-card-view',
        },
        {
          title: mentorintyBridgeApi.getEmbeddedTranslation(language, 'info').toLocaleUpperCase(),
          viewId: 'user-detail-page-info-view',
        },
        {
          title: mentorintyBridgeApi.getEmbeddedTranslation(language, 'getMeeting').toLocaleUpperCase(),
          viewId: 'user-detail-page-available-time-picker-view',
          params: {
            viewedUserMembershipConfig: session.generateMembershipConfigForRole(viewedUserRole),
            conversionConfig: {
              // viewedUserMembership will be provided by
              // the dvn-app-view-composite-view-linear with the name 'item'
              // we're setting the conversion config to convert the 'item' into 'viewedUserMembership'
              item: 'viewedUserMembership',
            }
          },
        },
        {
          title: mentorintyBridgeApi.getEmbeddedTranslation(language, 'meetings').toLocaleUpperCase(),
          viewId: 'user-detail-page-meeting-list-view',
          params: {
            guest1Id: groupId || userId,
            conversionConfig: {
              // viewedUserMembership will be provided by
              // the dvn-app-view-composite-view-linear with the name 'item'
              // we're setting the conversion config to convert the 'item.user._id' into 'guest2Id'
              'item.user._id': 'guest2Id',
            }
          },
        },
      ],
    }
  });
}

const mentornityUserDetailWrapperCss = "mentornity-user-detail-wrapper{display:block}";

let MentornityUserDetailWrapper = class {
  constructor(hostRef) {
    index$1.registerInstance(this, hostRef);
    this.weekStartDay = 'monday';
  }
  componentWillLoad() {
    const { isZoomAuthenticated, language, timeFormat, timeZone, weekStartDay, } = this;
    // set user's locale and time zone
    calendar.CalendarUtils.setTimeFormat(timeFormat);
    calendar.CalendarUtils.setTimeZone(timeZone);
    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$2.SozlukApi().setLanguage(language).setContents(sozlukEntries.sozlukEntries);
    const { context, headers } = session.getSessionDetails(this.groupId);
    this.mentornityCookieContext = context;
    this.user = session.getUser(context.userId);
    this.userSettings = session.getUserSettings(timeFormat, timeZone, language, isZoomAuthenticated);
    this.membership = session.generateMembershipForRole(context.role);
    this.mentornityBridgeApi = new mentorintyBridgeApi.MentornityBridgeApi(env.mentornityApiEndpoint, context, headers);
    instance.createMentornityApiInstance(env.mentornityApiEndpoint, headers)
      .getOrganisationConfig(context.organisationId)
      .then((response) => {
      this.organisationConfig = instance.Config.decode(response);
      this.mentornityBridgeApi.organisationConfig = instance.Config.decode(response);
    });
  }
  onAction(event) {
    const action = event.detail;
    switch (action.name) {
      case 'send-message':
        // called when user clicks the "Send Message" button from the detail page
        window.dispatchEvent(new CustomEvent('dvn.mentornity-user-detail-wrapper.send-message', {
          detail: {
            user: action.params.item,
          }
        }));
        break;
      case 'open-meeting-detail-after-creation':
      case 'open-meeting-detail-from-meeting-list':
        window.dispatchEvent(new CustomEvent('dvn.mentornity-user-detail-wrapper.open-meeting-detail', {
          detail: {
            meetingId: action.params.meetingId,
          }
        }));
        break;
    }
  }
  render() {
    const { groupId, language, membership, mentornityBridgeApi, mentornityCookieContext, organisationConfig, user, userSettings, viewedUserId, viewedUserRole, } = this;
    if (!organisationConfig) {
      return (index$1.h("div", { class: "d-flex justify-content-center pt-3" }, index$1.h("dvn-progress", { indefinite: true })));
    }
    return (index$1.h(index$1.Host, null, index$1.h("mentornity-root-wrapper", null, index$1.h("dvn-app-view-composite-view-linear", { apiSozluk: this.apiSozluk, apiData: mentornityBridgeApi, apiTakvim: mentornityBridgeApi, appConfig: getAppConfig(mentornityCookieContext, organisationConfig, language, viewedUserRole), params: {
        itemId: viewedUserId,
      }, user: user, userSettings: userSettings, membership: membership, view: getCompositeViewUIConfig(language, user._id, groupId, viewedUserRole) }))));
  }
};
MentornityUserDetailWrapper.style = mentornityUserDetailWrapperCss;

exports.mentornity_user_detail_wrapper = MentornityUserDetailWrapper;
