import { DetailViewConfig } from '@dvn/core/models/detail-view-config';
import { TableConfig } from '@dvn/core/models/table-config';
import { AtamaMemberPairsSelectionViewConfig } from '../../../../atama/src/views/atama-member-pair-selection-view-config';
import { commonUserInfoFields, convertMentornityFieldToDevingenField } from '../../api/mentorinty-bridge-api';
import { pairConfig } from '../../constants/pair-config';
import { getSessionDetails } from '../../util/session';
import { convertFieldsToFieldReferences, getAvailableMetadataFields, getPairConfigOptionsFromOrganisationConfig } from '../common-wrapper-util';
import { en, tr } from './i18n';
export function getPairSelectionParameters() {
  const { context } = getSessionDetails();
  // user is mentee, so the view config should say that the 'subscribed' is viewing the 'subscriber'
  return {
    memberToViewRefFieldId: 'subscribed',
    userRefFieldValue: context.userId,
    userRefFieldId: 'subscriber',
    viewIdToNavigateOnSelectionDone: 'pair-selection-done-page'
  };
}
export function getPairSelectionViewConfig(language, config) {
  if (!config) {
    return null;
  }
  const i18n = language === 'tr' ? tr : en;
  const profileFieldVisibility = config.profileFieldVisibilities.mentor;
  const defaultUserFields = ['title', 'bio', 'skills']
    .filter(id => profileFieldVisibility[id])
    .map(id => ({
    fieldId: id,
    lines: id === 'skills' ? 5 : 1,
  }));
  const infoCardFields = [...defaultUserFields, ...convertFieldsToFieldReferences(config.metadatas.mentor)]
    .filter(field => !['name', 'imageUrl'].includes(field.fieldId))
    .map(fieldConfig => {
    var _a;
    return (Object.assign(Object.assign({}, fieldConfig), { lines: ((_a = config.metadatas.mentor.find(f => f.id === fieldConfig.fieldId)) === null || _a === void 0 ? void 0 : _a.linesMax) || 1 }));
  });
  return AtamaMemberPairsSelectionViewConfig.decode({
    _id: 'pair-select-page',
    ui: {
      i18n: i18n.selectionView,
      main: {
        cardViewConfig: {
          header: {
            cover: {
              //   aspectRatio: 16 / 9,
              //   fieldId: 'imageUrl',
              size: 100,
            },
            image: {
              fieldId: 'imageUrl',
              placeholderFieldId: 'initials',
              size: 72,
            },
            title: {
              fieldId: 'name',
            },
          },
          body: {
            fields: infoCardFields,
          },
        },
      },
    },
    params: {},
    table: pairConfig(config, undefined, getPairConfigOptionsFromOrganisationConfig(config)),
  });
}
export function getUserDetailDialogParams(actionData) {
  return {
    itemId: actionData.params.item._id,
  };
}
export function getUserDetailDialogViewConfig(mentornityCookieContext, config) {
  if (!config) {
    return undefined;
  }
  const { organisationId, role } = mentornityCookieContext;
  const fields = getAvailableMetadataFields(role, 'mentor', config);
  const membershipFields = [...commonUserInfoFields, ...fields].map(convertMentornityFieldToDevingenField);
  const profileFieldVisibility = config.profileFieldVisibilities.mentor;
  const defaultUserFields = ['title', 'bio', 'skills']
    .filter(id => profileFieldVisibility[id])
    .map(id => ({ fieldId: id }));
  const detailCardFields = [...defaultUserFields, ...convertFieldsToFieldReferences(config.metadatas.mentor)]
    .filter(field => !['name', 'imageUrl'].includes(field.fieldId));
  return DetailViewConfig.decode({
    table: TableConfig.decode({
      base: organisationId,
      name: 'mentors',
      fields: membershipFields,
    }),
    ui: {
      cardConfig: {
        header: {
          title: {
            fieldId: 'name',
          },
        },
        body: {
          fields: detailCardFields,
        }
      }
    },
  });
}
