'use strict';

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

const index = require('./index-ce58ddc5.js');
const calendar = require('./calendar-12e78fe7.js');
const index$1 = require('./index-b2910095.js');
require('./apiBase-b14a8285.js');
require('./data-transfer-field-0ce05c1a.js');
require('./filter-d5040f65.js');
const instance = require('./instance-fba77445.js');
const mentorintyBridgeApi = require('./mentorinty-bridge-api-616ff4b9.js');
const env = require('./env-56a21d68.js');
const session = require('./session-fe19e012.js');
const sozlukEntries = require('./sozluk-entries-415b953f.js');
const atamaMemberPairDetailViewConfig = require('./atama-member-pair-detail-view-config-595fd8fd.js');
const spaces = require('./spaces-4a775c20.js');
const pairConfig = require('./pair-config-6e44fea9.js');
const commonWrapperUtil = require('./common-wrapper-util-f504304b.js');
require('./index-1f95aafc.js');
require('./_commonjsHelpers-206db00d.js');
require('./moment-d48a0164.js');
require('./BaseField-d019ade6.js');
require('./FieldModelGenerator-1af8e5c3.js');
require('./reference-field-dda66f2e.js');
require('./index-f92537c9.js');
require('./index-7e3bc620.js');
require('./date-25b104f6.js');
require('./index-9ea6c7b1.js');
require('./index-93271b8c.js');
require('./index-29b7cb16.js');
require('./index-792d710c.js');
require('./index-fa185e3b.js');
require('./attachment-3090e25e.js');
require('./data-model-9afb7f54.js');
require('./membership-310dd68e.js');
require('./table-config-73a193be.js');
require('./string-de672b69.js');
require('./User-e15e0b6d.js');
require('./CalendarConfig-7f8ef631.js');
require('./UserSettings-fc04eb54.js');
require('./cookie-ea977378.js');
require('./kimlikApi-f4f62100.js');
require('./index-33e96540.js');
require('./i18n-1b762664.js');
require('./pair-config-278a2924.js');
require('./view-config-1c8cc7cb.js');

const en = {
  detailView: {
    cancel: 'Cancel',
    createMeeting: 'Schedule Session',
    notScheduled: 'Not scheduled',
    dateFormatDay: 'DD MMM',
    dateFormatTime: 'HH:mm',
    endPair: 'Finish This Process',
    endPairConfirmationDescription: 'This action removes the pair from your account. You will not be able to schedule meetings with this person.',
    endPairConfirmationFinishPair: 'Finish the Process',
    endPairConfirmationTitle: 'Are you sure to end the process?',
    fetchConfigurationError: 'Getting configuration failed.',
    fetchItemError: 'Getting item failed.',
    info: 'INFO',
    meetings: 'MEETINGS',
    getMeeting: 'SELECT A DAY AND TIME',
    roleName: '',
    seeMore: 'See More',
    sendMessage: 'Send Message',
    viewDetails: 'View Details',
  },
};
const tr = {
  detailView: {
    cancel: 'Vazgeç',
    createMeeting: 'Toplantı Oluştur',
    notScheduled: 'Toplantı düzenlenmedi',
    endPair: 'Eşleşmeyi Sonlandır',
    endPairConfirmationDescription: 'Eşleşmeyi bitirdiğinizde bu kişi sizin listenizden silinecek ve bu kişi ile artık toplantı oluşturamayacaksınız.',
    endPairConfirmationFinishPair: 'Eşleşmeyi Sonlandır',
    endPairConfirmationTitle: 'Eşleşmeyi sonlandırmak istediğinize emin misiniz?',
    fetchConfigurationError: 'Ayarlar alınırken hata oluştu.',
    fetchItemError: 'Detaylar alınırken hata oluştu.',
    info: 'BİLGİ',
    meetings: 'TOPLANTILAR',
    getMeeting: 'TOPLANTI OLUŞTUR',
    roleName: '',
    seeMore: 'Daha Fazla Bilgi',
    sendMessage: 'Mesaj Gönder',
    viewDetails: 'Detayları Gör',
  },
};

function getPairDetailParameters(mentornityCookieContext, config) {
  const { role } = mentornityCookieContext;
  const viewingGroups = role === 'mentor' && config.menteeType === 'group';
  // if user is mentor, then the view config should say that the 'subscribed' is viewing the 'subscriber'
  // if user is mentee, then it should say otherwise
  const userRefFieldIdValue = role === 'mentor' ? 'subscribed' : 'subscriber';
  const memberToViewRefFieldIdValue = role === 'mentor' ? 'subscriber' : 'subscribed';
  const routeParams = session.getRouteParams(location.pathname);
  // don't show the message button if mentor is viewing group
  const showSendMessageButton = !viewingGroups;
  return {
    memberToViewRefFieldId: memberToViewRefFieldIdValue,
    userRefFieldId: userRefFieldIdValue,
    memberToViewRefFieldValue: new URLSearchParams(window.location.search).get('uid'),
    pairId: routeParams.id,
    viewIdToNavigateOnEndPair: 'pair-overview-page',
    showSendMessageButton,
  };
}
function getPairDetailViewConfig(mentornityCookieContext, language, config, goalConfig, viewConfigs) {
  const { role } = mentornityCookieContext;
  const viewName = role === 'mentor'
    ? instance.MentornityViewConfigViewName.MenteePairDetail
    : instance.MentornityViewConfigViewName.MentorPairDetail;
  const viewConfig = commonWrapperUtil.getViewConfigForViewName(viewConfigs, viewName);
  const i18n = language === 'tr' ? tr : en;
  const viewingGroups = role === 'mentor' && config.menteeType === 'group';
  // if user is mentor, then the view config should say that the 'subscribed' is viewing the 'subscriber'
  // if user is mentee, then it should say otherwise
  const userRefFieldIdValue = role === 'mentor' ? 'subscribed' : 'subscriber';
  const memberToViewRefFieldIdValue = role === 'mentor' ? 'subscriber' : 'subscribed';
  let infoSummaryCardFields = [];
  let infoDetailCardFields = [];
  if (viewConfig) {
    const pairOverviewConfig = viewConfig.dvnAppViewConfig;
    infoSummaryCardFields = commonWrapperUtil.filterUnavailableMetadataFields(role, config, pairOverviewConfig.ui.main.infoSummaryCardViewConfig.body.fields);
    infoDetailCardFields = commonWrapperUtil.filterUnavailableMetadataFields(role, config, pairOverviewConfig.ui.main.infoDetailCardViewConfig.body.fields);
  }
  else {
    const profileFieldVisibility = role === 'mentor' ? config.profileFieldVisibilities.mentee : config.profileFieldVisibilities.mentor;
    const defaultUserFields = ['title', 'bio', 'skills'].filter(id => profileFieldVisibility[id]).map(id => ({ fieldId: id }));
    const defaultGroupFields = ['description', 'members'].map(id => ({ fieldId: id, showTitle: true }));
    const fields = viewingGroups ? [] : commonWrapperUtil.getAvailableMetadataFields(role, config);
    infoDetailCardFields = (viewingGroups ? defaultGroupFields : [...defaultUserFields, ...commonWrapperUtil.convertFieldsToFieldReferences(fields)])
      .filter(field => !['name', 'imageUrl'].includes(field.fieldId));
    infoSummaryCardFields = infoDetailCardFields
      .slice(0, 3)
      .map(fieldConfig => (Object.assign(Object.assign({}, fieldConfig), { lines: 1 }))); // to trim long texts
  }
  return atamaMemberPairDetailViewConfig.AtamaMemberPairDetailViewConfig.decode({
    _id: 'pair-detail-page',
    i18nEntryId: 'pair-detail-page',
    ui: {
      i18n: Object.assign(Object.assign({}, i18n.detailView), { roleName: getLocalisedRoleName(config, role, language, viewingGroups) }),
      main: {
        infoSummaryCardViewConfig: {
          header: {},
          body: {
            fields: infoSummaryCardFields,
          },
          footer: {}
        },
        infoDetailCardViewConfig: {
          header: {},
          body: {
            fields: infoDetailCardFields,
          },
          footer: {}
        },
      },
    },
    space: spaces.spaces['space-1'],
    title: 'Pair Details',
    type: 'atama-member-pair-detail-view',
    table: pairConfig.pairConfig(config, goalConfig, commonWrapperUtil.getPairConfigOptionsFromOrganisationConfig(config)),
    params: {
      userRefFieldId: {
        required: true,
        value: userRefFieldIdValue
      },
      memberToViewRefFieldId: {
        required: true,
        value: memberToViewRefFieldIdValue,
      },
      memberToViewRefFieldValue: {
        required: true,
      },
      pairId: {
        required: true,
      },
      viewIdToNavigateOnEndPair: {
        required: true,
        value: 'pair-overview-page',
      },
    },
  });
}
const roleNameMaps = {
  en: {
    group: {
      company: 'Company',
      group: 'Group',
      startup: 'Startup',
    },
    mentee: {
      attendee: 'Attendee',
      candidate: 'Candidate',
      coachee: 'Coachee',
      consultee: 'Consultee',
      entrepreneur: 'Entrepreneur',
      member: 'Member',
      mentee: 'Mentee',
      student: 'Student',
    },
    mentor: {
      alumnus: 'Alumnus',
      angel: 'Angel',
      authority: 'Company Rep.',
      coach: 'Coach',
      consultant: 'Consultant',
      expert: 'Expert',
      host: 'Host',
      mentor: 'Mentor',
      partner: 'Partner',
    },
  },
  tr: {
    group: {
      company: 'Şirket',
      group: 'Grup',
      startup: 'Girişim',
    },
    mentee: {
      attendee: 'Katılımcı',
      candidate: 'Aday',
      coachee: 'Danışan',
      consultee: 'Danışan',
      entrepreneur: 'Girişimci',
      member: 'Üye',
      mentee: 'Menti',
      student: 'Öğrenci',
    },
    mentor: {
      alumnus: 'Mezun',
      angel: 'Melek',
      authority: 'Yetkili',
      coach: 'Koç',
      consultant: 'Danışman',
      expert: 'Uzman',
      host: 'Düzenleyici',
      mentor: 'Mentor',
      partner: 'Partner',
    },
  }
};
const getLocalisedRoleName = (config, accountRole, language, viewingGroups) => {
  const otherRole = accountRole === 'mentor' ? (viewingGroups ? 'group' : 'mentee') : 'mentor';
  const roleNameConstant = accountRole === 'mentor'
    ? (viewingGroups ? config.termReplacements.group : config.termReplacements.mentee)
    : config.termReplacements.mentor;
  return (roleNameMaps[language] || roleNameMaps.en)[otherRole][roleNameConstant];
};

let MentornityPairDetailWrapper = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.weekStartDay = 'monday';
  }
  onAction(event) {
    const action = event.detail;
    switch (action.name) {
      case 'send-message':
        window.dispatchEvent(new CustomEvent('dvn.atama-pairs.send-message', {
          detail: {
            user: action.data.item.user,
          }
        }));
        break;
      case 'create-meeting':
        const meetingConfig = action.data.meetingConfig;
        window.dispatchEvent(new CustomEvent('dvn.atama-pairs.create-meeting', {
          detail: {
            goal: {
              identifier: meetingConfig.id,
              meetingTitle: meetingConfig.name,
            },
            user: action.data.item.user,
          }
        }));
        break;
      case 'open-meeting-detail':
        window.dispatchEvent(new CustomEvent('dvn.atama-pairs.open-meeting-detail', {
          detail: {
            meetingId: action.data.meeting._id,
          }
        }));
        break;
      case 'open-meeting-detail-from-meeting-list':
        window.dispatchEvent(new CustomEvent('dvn.atama-pairs.open-meeting-detail', {
          detail: {
            meetingId: action.params.meetingId,
          }
        }));
        break;
    }
    if (action.type === 'navigation') {
      const { direction, resetHistory, viewId } = action;
      if (direction === 'forward' && resetHistory && viewId === 'pair-overview-page') {
        // user ended the subscription, go to pair list page
        window.dispatchEvent(new CustomEvent('dvn.atama-pairs.open-pair-overview-page', {}));
      }
    }
  }
  async componentWillLoad() {
    const { isZoomAuthenticated, language, timeFormat, dateFormat, timeZone, 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.user = session.getUser(context.userId);
    this.userSettings = session.getUserSettings(timeFormat, dateFormat, timeZone, language, isZoomAuthenticated);
    this.membership = session.generateMembershipForRole(context.role);
    this.mentornityBridgeApi = new mentorintyBridgeApi.MentornityBridgeApi(env.mentornityApiEndpoint, context, headers);
    const mentornityApi = instance.createMentornityApiInstance(env.mentornityApiEndpoint, headers);
    const getViewConfigsResponse = await mentornityApi.getViewConfigs(context.organisationId)
      .catch(error => this.error = error);
    if (!getViewConfigsResponse)
      return;
    const viewConfigs = getViewConfigsResponse.results;
    const organisationConfig = await mentornityApi.getOrganisationConfig(context.organisationId)
      .catch(error => this.error = error);
    if (!organisationConfig)
      return;
    this.organisationConfig = organisationConfig;
    const goalConfig = await mentornityApi.getOrganisationMeetingGoalConfig(context.organisationDomain)
      .catch(error => this.error = error);
    this.goalConfig = goalConfig;
    this.atamaMemberPairDetailViewConfig = getPairDetailViewConfig(context, language, organisationConfig, goalConfig, viewConfigs);
  }
  render() {
    const { atamaMemberPairDetailViewConfig, membership, mentornityBridgeApi, mentornityCookieContext, organisationConfig, user, userSettings, } = this;
    if (!atamaMemberPairDetailViewConfig) {
      return null;
    }
    const params = getPairDetailParameters(mentornityCookieContext, organisationConfig);
    return (index.h("mentornity-root-wrapper", null, index.h("dvn-app-view-atama-member-pair-detail-view", { apiAtama: mentornityBridgeApi, apiData: mentornityBridgeApi, apiTakvim: mentornityBridgeApi, apiUye: mentornityBridgeApi, apiSozluk: this.apiSozluk, membership: membership, user: user, userSettings: userSettings, params: params, view: atamaMemberPairDetailViewConfig })));
  }
};

exports.mentornity_pair_detail_wrapper = MentornityPairDetailWrapper;
