import { r as registerInstance, h } 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 { e as MentornityViewConfigViewName, c as createMentornityApiInstance } from './instance-db63ecb7.js';
import { M as MentornityBridgeApi } from './mentorinty-bridge-api-f70621dd.js';
import { f as getRouteParams, h as sozlukCalendarEntryEn, i as sozlukCalendarEntryTr, j as sozlukCalendarEntryPtBr, s as sozlukEntries, g as getSessionDetails, k as getUserSettings, c as generateMembershipForRole, a as mentornityApiEndpoint } from './session-a602596d.js';
import { A as AtamaMemberPairDetailViewConfig } from './atama-member-pair-detail-view-config-ba21c130.js';
import { s as spaces } from './spaces-a5a0cc70.js';
import { p as pairConfig } from './pair-config-851f8fa5.js';
import { b as getPairConfigOptionsFromOrganisationConfig, g as getViewConfigForViewName, f as filterUnavailableMetadataFields, a as getAvailableMetadataFields, c as convertFieldsToFieldReferences } from './common-wrapper-util-62bbacf2.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 './pair-config-1713abb7.js';
import './view-config-2fc2ba10.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',
    goToSessionPage: 'Go to Session Page'
  },
};
const pt_br = {
  detailView: {
    cancel: 'Cancelar',
    createMeeting: 'Agendar sessão',
    notScheduled: 'Não agendado',
    dateFormatDay: 'DD MMM',
    dateFormatTime: 'HH:mm',
    endPair: 'Concluir este processo',
    endPairConfirmationDescription: 'Esta ação remove o par de sua conta. Você não poderá agendar reuniões com esta pessoa.',
    endPairConfirmationFinishPair: 'Finalize o processo',
    endPairConfirmationTitle: 'Tem certeza de encerrar o processo?',
    fetchConfigurationError: 'Falha ao obter configuração.',
    fetchItemError: 'Falha ao obter item.',
    info: 'INFORMAÇÕES',
    meetings: 'ENCONTROS',
    getMeeting: 'SELECIONE UM DIA E HORÁRIO',
    roleName: '',
    seeMore: 'Ver mais',
    sendMessage: 'Enviar mensagem',
    viewDetails: 'Ver detalhes',
    goToSessionPage: 'Ir para a página da sessão'
  },
};
const tr = {
  detailView: {
    cancel: 'Vazgeç',
    createMeeting: 'Toplantı Oluştur',
    notScheduled: 'Toplantı düzenlenmedi',
    dateFormatDay: 'DD MMM',
    dateFormatTime: 'HH:mm',
    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',
    goToSessionPage: 'Toplantı sayfasına git'
  },
};

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 = 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'
    ? MentornityViewConfigViewName.MenteePairDetail
    : MentornityViewConfigViewName.MentorPairDetail;
  const viewedUserRole = role === 'mentor' ? 'mentee' : 'mentor';
  const viewConfig = getViewConfigForViewName(viewConfigs, viewName);
  // set English default language
  let i18n = en;
  switch (language) {
    case 'tr':
      i18n = tr;
      break;
    case 'pt-br':
      i18n = pt_br;
  }
  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 = filterUnavailableMetadataFields(role, config, pairOverviewConfig.ui.main.infoSummaryCardViewConfig.body.fields);
    infoDetailCardFields = 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 ? [] : getAvailableMetadataFields(role, viewedUserRole, config);
    infoDetailCardFields = (viewingGroups ? defaultGroupFields : [...defaultUserFields, ...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.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['space-1'],
    title: 'Pair Details',
    type: 'atama-member-pair-detail-view',
    table: pairConfig(config, goalConfig, 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];
};

const MentornityPairDetailWrapper = class {
  constructor(hostRef) {
    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
    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);
    this.membership = generateMembershipForRole(context.role);
    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 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 (h("mentornity-root-wrapper", null, 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 })));
  }
};

export { MentornityPairDetailWrapper as mentornity_pair_detail_wrapper };
