import { d as decodeFields, T as TableConfig } from './table-config-3820fb34.js';
import { D as DetailViewConfig } from './detail-view-config-47244869.js';
import { A as AtamaMemberPairsOverviewViewConfig } from './atama-member-pairs-overview-view-config-3b3bcabe.js';
import { d as InfoVisibility, e as MentornityViewConfigViewName } from './instance-db63ecb7.js';
import { c as commonUserInfoFields } from './mentorinty-bridge-api-f70621dd.js';
import { p as pairConfig } from './pair-config-851f8fa5.js';
import { g as getViewConfigForViewName, f as filterUnavailableMetadataFields, a as getAvailableMetadataFields, c as convertFieldsToFieldReferences, b as getPairConfigOptionsFromOrganisationConfig } from './common-wrapper-util-62bbacf2.js';

const en = {
  view: {
    accept: 'Accept',
    fetchConfigurationError: 'Getting configuration failed.',
    fetchListError: 'Fetching list failed.',
    noPairsMessage: 'You don\'t have any pairs.',
    noReceivedRequests: 'There are no pending requests.',
    pairs: 'Pairs',
    receivedRequests: 'Received Requests',
    reject: 'Reject',
    selectionCardActionTint: 'secondary',
    selectionCardActionLabel: 'Go to selection page',
    selectionCardMessage: 'You can view all available users and send them requests.',
    selectionCardTint: 'primary',
    selectionCardTitle: 'Selection is on!',
    sentOnDateFormat: 'DD MMM YYYY, HH:mm',
    statusLabels: {
      accepted: 'Accepted',
      canceled: 'Canceled',
      completed: 'Completed',
      rejected: 'Rejected',
      requested: 'Requested',
    },
    viewAndMeet: 'View & Meet',
  },
};
const tr = {
  view: {
    accept: 'Kabul Et',
    fetchConfigurationError: 'Ayarlar alınırken hata oluştu.',
    fetchListError: 'Seçim listesi alınırken hata oluştu.',
    noPairsMessage: 'Eşleştiğiniz kimse yok.',
    noReceivedRequests: 'Onay bekleyen istek yok.',
    pairs: 'Eşleşmeler',
    receivedRequests: 'Alınan İstekler',
    reject: 'Reddet',
    selectionCardActionTint: 'secondary',
    selectionCardActionLabel: 'Seçim sayfasına git',
    selectionCardMessage: 'Müsait olan tüm kullanıcıları görüp onlara istek gönderebilirsiniz.',
    selectionCardTint: 'primary',
    selectionCardTitle: 'Seçim başladı!',
    sentOnDateFormat: 'DD MMM YYYY, HH:mm',
    statusLabels: {
      accepted: 'Onaylandı',
      canceled: 'Reddedildi',
      completed: 'Sonlandırıldı',
      rejected: 'Reddedildi',
      requested: 'Gönderildi',
    },
    viewAndMeet: 'Detay & Toplantılar',
  },
};

function getPairOverviewParameters(mentornityCookieContext) {
  const { role } = mentornityCookieContext;
  // 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';
  return {
    memberToViewRefFieldId: memberToViewRefFieldIdValue,
    userRefFieldId: userRefFieldIdValue,
    viewIdToNavigateToSelectPair: 'pair-selection-page',
    viewIdToViewRequestSender: 'user-page',
  };
}
function getPairOverviewViewConfig(mentornityCookieContext, language, config, viewConfigs) {
  const i18n = language === 'tr' ? tr : en;
  const { role } = mentornityCookieContext;
  const viewingGroups = role === 'mentor' && config.menteeType === 'group';
  let cardBodyFields = [];
  const viewName = role === 'mentor'
    ? MentornityViewConfigViewName.MenteePairList
    : MentornityViewConfigViewName.MentorPairList;
  const viewConfig = getViewConfigForViewName(viewConfigs, viewName);
  if (viewConfig) {
    const pairOverviewConfig = viewConfig.dvnAppViewConfig;
    cardBodyFields = filterUnavailableMetadataFields(role, config, pairOverviewConfig.ui.main.cardViewConfig.body.fields);
  }
  else {
    const profileFieldVisibility = role === 'mentor' ? config.profileFieldVisibilities.mentee : config.profileFieldVisibilities.mentor;
    const defaultUserFields = ['title', 'bio', 'skills', 'imagePlaceholderValue'].filter(id => profileFieldVisibility[id]).map(id => ({ fieldId: id }));
    const defaultGroupFields = ['description', 'imagePlaceholderValue'].map(id => ({ fieldId: id }));
    const viewedUserRole = role === 'mentor' ? 'mentee' : 'mentor';
    const fields = viewingGroups ? [] : getAvailableMetadataFields(role, viewedUserRole, config);
    cardBodyFields = (viewingGroups ? defaultGroupFields : [...defaultUserFields, ...convertFieldsToFieldReferences(fields)])
      .slice(0, 3)
      .map(fieldConfig => (Object.assign(Object.assign({}, fieldConfig), { lines: 1 }))) // to trim long texts
      .filter(field => !['name', 'imageUrl', 'imagePlaceholderValue'].includes(field.fieldId));
  }
  return AtamaMemberPairsOverviewViewConfig.decode({
    _id: 'pair-overview-page',
    ui: {
      i18n: i18n.view,
      main: {
        cardViewConfig: {
          header: {
            cover: {
              size: 100,
            },
            image: {
              fieldId: 'imageUrl',
              placeholderFieldId: 'imagePlaceholderValue',
              shape: viewingGroups ? 'rounded' : undefined,
              size: 72,
            },
            title: {
              fieldId: viewingGroups ? 'title' : 'name',
            },
          },
          body: {
            fields: cardBodyFields,
          },
          footer: {
            actions: [
              {
                data: {
                  type: 'navigation',
                  direction: 'forward',
                  placement: 'view',
                  viewId: 'subscriptions',
                  params: {
                    conversionConfig: {
                      'item._id': 'memberToViewRefFieldValue',
                      'item.subscription._id': 'pairId',
                    }
                  }
                },
                ui: {
                  label: i18n.view.viewAndMeet || 'View & Meet',
                  name: 'open-pair-detail-view',
                  view: 'ghost',
                }
              }
            ]
          }
        },
      },
    },
    params: {},
    table: pairConfig(config, undefined, getPairConfigOptionsFromOrganisationConfig(config)),
  });
}
function getUserDetailDialogParams(actionData) {
  return {
    itemId: actionData.params.item._id,
  };
}
function getUserDetailDialogViewConfig(mentornityCookieContext, config) {
  if (!config) {
    return undefined;
  }
  const { organisationId, role } = mentornityCookieContext;
  const profileFieldVisibility = role === 'mentor' ? config.profileFieldVisibilities.mentee : config.profileFieldVisibilities.mentor;
  const viewedUserRole = role === 'mentor' ? 'mentee' : 'mentor';
  const defaultUserFields = ['title', 'bio', 'skills'].filter(id => profileFieldVisibility[id]).map(id => ({ fieldId: id }));
  const fields = getAvailableMetadataFields(role, viewedUserRole, config);
  const detailViewMembershipFields = decodeFields([...commonUserInfoFields, ...fields]);
  const detailViewCardFields = [...defaultUserFields, ...convertFieldsToFieldReferences(fields)]
    .filter(field => !['name', 'imageUrl'].includes(field.fieldId));
  const showMessageButton = [
    InfoVisibility.allMentees,
    InfoVisibility.everyone,
  ].includes(config.conversationPermissions.mentor);
  return DetailViewConfig.decode({
    table: TableConfig.decode({
      base: organisationId,
      name: 'mentees',
      fields: detailViewMembershipFields,
    }),
    ui: {
      cardConfig: {
        header: {
          title: {
            fieldId: 'name',
          },
          actions: showMessageButton ? [
            {
              ui: {
                label: 'Send Message',
                name: 'send-message',
              }
            }
          ] : [],
        },
        body: {
          fields: detailViewCardFields,
        }
      }
    },
  });
}

export { getUserDetailDialogParams as a, getUserDetailDialogViewConfig as b, getPairOverviewParameters as c, getPairOverviewViewConfig as g };
