import { r as registerInstance, h } from './index-acdc1ac0.js';
import './index-d9d18e9c.js';
import { D as DataModel } from './data-model-bb5789f5.js';
import './BaseField-d94c5b14.js';
import './FieldModelGenerator-755e3a85.js';
import './date-b270be76.js';
import './index-a95fa2f4.js';
import './table-config-9f3dee34.js';
import './string-2d991277.js';
import './membership-config-1607e716.js';
import './User-e14f1ece.js';
import './_commonjsHelpers-63c253cd.js';
import './index-fd2b14ae.js';
import './kimlikApi-81acfec6.js';
import './data-transfer-field-1ad95e08.js';
import './filter-cbaa3d7d.js';
import './cookie-d9098150.js';
import './moment-6f6ab70c.js';
import { C as CalendarUtils } from './calendar-a511fee1.js';
import './view-config-2a7feb02.js';
import './attachment-8831acff.js';
import { c as createMentornityApiInstance } from './instance-b3864e36.js';
import { a as getRouteParams, g as getSessionDetails, m as mentornityApiEndpoint } from './session-78c3c986.js';
import { s as spaces } from './spaces-8bb938bc.js';
import './index-c43f1f2e.js';
import { b as convertFieldsToFieldReferences, g as getFieldsToShow, d as getPairConfigOptionsFromOrganisationConfig, M as MentornityBridgeApi } from './common-wrapper-util-c1020679.js';
import './pair-config-b11a5ee7.js';
import { A as AtamaMemberPairDetailViewConfig } from './atama-member-pair-detail-view-config-ed4b1616.js';
import { p as pairConfig } from './pair-config-214c1b1e.js';

const en = {
  detailView: {
    cancel: 'Cancel',
    createMeeting: 'Schedule Session',
    meetingWillBeCreated: 'Will be 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',
    roleName: '',
    seeMore: 'See More',
    sendMessage: 'Send Message',
    viewDetails: 'View Details',
  },
};
const tr = {
  detailView: {
    cancel: 'Vazgeç',
    createMeeting: 'Toplantı Oluştur',
    meetingWillBeCreated: 'Toplantı oluşturulacak',
    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',
    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 = getRouteParams(location.pathname);
  const showAvailabilitiesButton = role === 'mentee' && config.meetingSettings.mentorsCanCreateAvailability;
  const showCreateMeetingButton = (role === 'mentee' && config.meetingSettings.menteesCanCreateMeeting) ||
    (role === 'mentor' && config.meetingSettings.mentorsCanCreateMeeting);
  // 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',
    showAvailabilitiesButton,
    showCreateMeetingButton,
    showSendMessageButton,
  };
}
function getPairDetailViewConfig(mentornityCookieContext, language, config, goalConfig) {
  if (!config) {
    return null;
  }
  const i18n = language === 'tr' ? tr : en;
  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 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 ? [] : getFieldsToShow(role, config);
  const infoDetailCardFields = (viewingGroups ? defaultGroupFields : [...defaultUserFields, ...convertFieldsToFieldReferences(fields)])
    .filter(field => !['fullName', 'imageUrl'].includes(field.fieldId));
  const 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',
    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][otherRole][roleNameConstant];
};

const MentornityPairDetailWrapper = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
  }
  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 'view-availabilities':
        window.dispatchEvent(new CustomEvent('dvn.atama-pairs.view-availabilities', {
          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;
    }
    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', {}));
      }
    }
  }
  componentWillLoad() {
    const { context, headers } = getSessionDetails();
    this.mentornityBridgeApi = new MentornityBridgeApi(mentornityApiEndpoint, context, headers);
    const mentornityApi = createMentornityApiInstance(mentornityApiEndpoint, headers);
    mentornityApi.getOrganisationMeetingGoalConfig(context.organisationDomain).then(response => this.goalConfig = response);
    mentornityApi.getOrganisationConfig(context.organisationId).then((response) => {
      this.organisationConfig = response;
    });
  }
  render() {
    // set user's locale and time zone
    const { goalConfig, language, mentornityBridgeApi, organisationConfig, timeZone } = this;
    CalendarUtils.setLocale(language);
    CalendarUtils.setTimeZone(timeZone);
    const { context } = getSessionDetails();
    const pairDetailViewConfig = getPairDetailViewConfig(context, language, organisationConfig, goalConfig);
    if (!pairDetailViewConfig) {
      return null;
    }
    return (h("mentornity-root-wrapper", null, h("dvn-app-view-atama-member-pair-detail-view", { apiAtama: mentornityBridgeApi, apiData: mentornityBridgeApi, apiUye: mentornityBridgeApi, membership: DataModel.decode({}), params: getPairDetailParameters(context, organisationConfig), view: pairDetailViewConfig })));
  }
};

export { MentornityPairDetailWrapper as mentornity_pair_detail_wrapper };
