'use strict';

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

const index = require('./index-ce58ddc5.js');
const index$2 = require('./index-407b6960.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 detailViewConfig = require('./detail-view-config-ba51db6c.js');
const tableConfig = require('./table-config-73a193be.js');
const pairConfig = require('./pair-config-278a2924.js');
const viewConfig = require('./view-config-1c8cc7cb.js');
const pairConfig$1 = require('./pair-config-6e44fea9.js');
const commonWrapperUtil = require('./common-wrapper-util-f504304b.js');
require('./state-tunnel-786a62ce.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('./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');

class AtamaMemberPairsSelectionViewConfig extends viewConfig.DvnAppViewConfig {
  static decode(json) {
    const model = Object.assign(Object.create(AtamaMemberPairsSelectionViewConfig.prototype), json);
    model.table = pairConfig.PairConfig.decode(model.table);
    return model;
  }
}

const en = {
  selectionView: {
    cancel: 'Cancel',
    fetchConfigurationError: 'Getting configuration failed.',
    fetchSelectionListError: 'Getting selection list failed.',
    fetchSentRequestListError: 'Getting sent requests failed.',
    listToSelect: 'LIST TO SELECT',
    maxLimitMessage: 'You can send max {selectionLimit} requests at a time.',
    noItemToSelect: 'There are no users to select.',
    noItemMatchesFilter: 'No users match your search.',
    noSentRequests: 'You haven\'t sent any requests.',
    pairRequestIsSent: 'Request is sent.',
    searchPlaceholder: 'Search by any info',
    seeDetails: 'See Details',
    select: 'Select',
    sendMessage: 'Message',
    sentRequests: 'SENT REQUESTS',
    sentOnDateFormat: 'DD MMM YYYY, HH:mm',
    selectionConfirmationDialogTitle: 'Are you sure to select this user?',
    selectionConfirmationDialogMessageForApproval: 'The user will receive a notification and the process will start after the user approves the request. Requests can only be canceled by the program administration.',
    selectionConfirmationDialogMessage: 'The user will receive a notification and the process will start immediately. Pairs can only be canceled by the program administration.',
    statusLabels: {
      accepted: 'Accepted',
      canceled: 'Canceled',
      completed: 'Completed',
      rejected: 'Rejected',
      requested: 'Requested',
    },
    yes: 'Yes',
  },
};
const tr = {
  selectionView: {
    cancel: 'Vazgeç',
    fetchConfigurationError: 'Ayarlar alınırken hata oluştu.',
    fetchSelectionListError: 'Seçim listesi alınırken hata oluştu.',
    fetchSentRequestListError: 'Gönderilen istek listesi alınırken hata oluştu.',
    listToSelect: 'Seçim Listesi',
    maxLimitMessage: 'En fazla {selectionLimit} istek gönderebilirsiniz.',
    noItemToSelect: 'Seçecek kullanıcı bulunamadı.',
    noItemMatchesFilter: 'Arama ölçütünüzle eşleşen kullanıcı bulunamadı.',
    noSentRequests: 'Henüz bir istek göndermediniz.',
    pairRequestIsSent: 'İstek gönderildi.',
    searchPlaceholder: 'Kullanıcı ara',
    seeDetails: 'Detaylar',
    select: 'Seç',
    sendMessage: 'Mesaj',
    sentRequests: 'Gönderilen İstekler',
    sentOnDateFormat: 'DD MMM YYYY, HH:mm',
    selectionConfirmationDialogTitle: 'Bu kullanıcıyı seçmek istediğinize emin misiniz?',
    selectionConfirmationDialogMessageForApproval: 'İstek gönderildikten sonra kullanıcıya bildirim gönderilecek ve süreç, kullanıcı isteği kabul ettikten sonra başlayacak. İstekler sadece yönetim tarafından iptal edilebilir.',
    selectionConfirmationDialogMessage: 'Kullanıcıya bildirim gönderilecek ve süreç anında başlayacak. Süreç sadece yönetim kontrolünde bitirilebilir.',
    statusLabels: {
      accepted: 'Onaylandı',
      canceled: 'İptal Edildi',
      completed: 'Sonlandırıldı',
      rejected: 'Reddedildi',
      requested: 'Gönderildi',
    },
    yes: 'Evet',
  },
};

function getPairSelectionParameters() {
  const { context } = session.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'
  };
}
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, ...commonWrapperUtil.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',
              size: 72,
            },
            title: {
              fieldId: 'name',
            },
          },
          body: {
            fields: infoCardFields,
          },
        },
      },
    },
    params: {},
    table: pairConfig$1.pairConfig(config, undefined, commonWrapperUtil.getPairConfigOptionsFromOrganisationConfig(config)),
  });
}
function getUserDetailDialogParams(actionData) {
  return {
    itemId: actionData.params.item._id,
  };
}
function getUserDetailDialogViewConfig(mentornityCookieContext, config) {
  if (!config) {
    return undefined;
  }
  const { organisationId, role } = mentornityCookieContext;
  const fields = commonWrapperUtil.getAvailableMetadataFields(role, config);
  const membershipFields = [...mentorintyBridgeApi.commonUserInfoFields, ...fields].map(mentorintyBridgeApi.convertMentornityFieldToDevingenField);
  const profileFieldVisibility = config.profileFieldVisibilities.mentor;
  const defaultUserFields = ['title', 'bio', 'skills']
    .filter(id => profileFieldVisibility[id])
    .map(id => ({ fieldId: id }));
  const detailCardFields = [...defaultUserFields, ...commonWrapperUtil.convertFieldsToFieldReferences(config.metadatas.mentor)]
    .filter(field => !['name', 'imageUrl'].includes(field.fieldId));
  return detailViewConfig.DetailViewConfig.decode({
    table: tableConfig.TableConfig.decode({
      base: organisationId,
      name: 'mentors',
    }),
    ui: {
      fields: membershipFields,
      cardConfig: {
        header: {
          title: {
            fieldId: 'name',
          },
        },
        body: {
          fields: detailCardFields,
        }
      }
    },
  });
}

let MentornityPairsOverviewWrapper = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
  }
  onAction(event) {
    const action = event.detail;
    if (action.name === 'send-message') {
      // called when mentor clicks the "Send Message" button from the mentor selection card
      window.dispatchEvent(new CustomEvent('dvn.atama-pairs.send-message', {
        detail: {
          user: action.params.item,
        }
      }));
    }
    if (action.name === 'view-details') {
      // called when mentor clicks the "Send Message" button from the mentor selection card
      this.viewUserDetailDialogActionData = action;
    }
  }
  componentWillLoad() {
    const { language, timeZone } = this;
    calendar.CalendarUtils.setLocale(language);
    calendar.CalendarUtils.setTimeZone(timeZone);
    const { context, headers } = session.getSessionDetails();
    this.mentornityBridgeApi = new mentorintyBridgeApi.MentornityBridgeApi(env.mentornityApiEndpoint, context, headers);
    this.apiSozluk = new index$1.SozlukApi().setLanguage(language).setContents(sozlukEntries.sozlukEntries);
    instance.createMentornityApiInstance(env.mentornityApiEndpoint, headers)
      .getOrganisationConfig(context.organisationId).then((response) => this.organisationConfig = response);
  }
  render() {
    const { context } = session.getSessionDetails();
    const { apiSozluk, language, mentornityBridgeApi, organisationConfig, viewUserDetailDialogActionData } = this;
    const pairSelectionViewConfig = getPairSelectionViewConfig(language, organisationConfig);
    if (!pairSelectionViewConfig) {
      return (index.h("div", { class: "d-flex justify-content-center pt-3" }, index.h("dvn-progress", { indefinite: true })));
    }
    return (index.h(index.Host, { style: { display: 'block' } }, index.h("mentornity-root-wrapper", null, index.h("dvn-app-view-atama-member-pair-selection-view", { apiAtama: mentornityBridgeApi, apiUye: mentornityBridgeApi, notifier: this.notifier, params: getPairSelectionParameters(), view: pairSelectionViewConfig }), viewUserDetailDialogActionData &&
      index.h("dvn-dialog", { raw: true, shown: true, onDismiss: () => this.viewUserDetailDialogActionData = undefined }, index.h("dvn-app-view-detail-view-card", { apiSozluk: apiSozluk, apiData: mentornityBridgeApi, id: "user-page", params: getUserDetailDialogParams(viewUserDetailDialogActionData), view: getUserDetailDialogViewConfig(context, organisationConfig) })))));
  }
};
index$2.injectNotifier(MentornityPairsOverviewWrapper);

exports.mentornity_pair_selection_wrapper = MentornityPairsOverviewWrapper;
