import { r as registerInstance, h, H as Host } from './index-ecdfb761.js';
import { i as injectNotifier } from './index-1e6a7311.js';
import { C as CalendarUtils } from './calendar-470c802a.js';
import { S as SozlukApi } from './index-3bf9b308.js';
import './apiBase-6015f41f.js';
import './data-transfer-field-2f305919.js';
import './filter-cbaa3d7d.js';
import { g as getSessionDetails, m as mentornityApiEndpoint, c as createMentornityApiInstance } from './session-2a491341.js';
import { c as commonUserInfoFields, b as convertMentornityFieldToDevingenField, M as MentornityBridgeApi } from './mentorinty-bridge-api-5ca2d652.js';
import { s as sozlukEntries } from './sozluk-entries-1e8f5234.js';
import { D as DetailViewConfig } from './detail-view-config-23af2b0d.js';
import { T as TableConfig } from './table-config-d73a72ab.js';
import { P as PairConfig } from './pair-config-13b5a7c1.js';
import { D as DvnAppViewConfig } from './view-config-1ed8c59f.js';
import { p as pairConfig } from './pair-config-a31d66bf.js';
import { c as convertFieldsToFieldReferences, b as getPairConfigOptionsFromOrganisationConfig, a as getAvailableMetadataFields } from './common-wrapper-util-e4afa19b.js';
import './state-tunnel-04c0b67a.js';
import './index-a3ca021c.js';
import './_commonjsHelpers-27f122dd.js';
import './moment-65eca6b3.js';
import './BaseField-0b01dc2c.js';
import './membership-b6639471.js';
import './data-model-88af49fc.js';
import './string-3065a411.js';
import './User-72c4643a.js';
import './UserSettings-7e4170a7.js';
import './cookie-5d9f5819.js';
import './kimlik-api-fddeac81.js';
import './index-d3bd30bd.js';
import './FieldModelGenerator-378c8613.js';
import './reference-field-a5b414d1.js';
import './index-61dcd269.js';
import './FieldGenerator-3ae403b2.js';
import './date-1bc489bd.js';
import './index-4e451db4.js';
import './index-23baeeef.js';
import './index-09efdc01.js';
import './index-150b6a59.js';
import './index-e66e8eca.js';
import './attachment-961dd228.js';
import './CalendarConfig-412d1b0f.js';
import './i18n-09a07b97.js';
import './i18n-0e757ca5.js';

class AtamaMemberPairsSelectionViewConfig extends DvnAppViewConfig {
  static decode(json) {
    const model = Object.assign(Object.create(AtamaMemberPairsSelectionViewConfig.prototype), json);
    model.table = 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 } = 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, ...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)),
  });
}
function getUserDetailDialogParams(actionData) {
  return {
    itemId: actionData.params.item._id,
  };
}
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,
        }
      }
    },
  });
}

const MentornityPairsOverviewWrapper = class {
  constructor(hostRef) {
    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;
    CalendarUtils.setLocale(language);
    CalendarUtils.setTimeZone(timeZone);
    const { context, headers } = getSessionDetails();
    this.mentornityBridgeApi = new MentornityBridgeApi(mentornityApiEndpoint, context, headers);
    this.apiSozluk = new SozlukApi().setLanguage(language).setContents(sozlukEntries);
    createMentornityApiInstance(mentornityApiEndpoint, headers)
      .getOrganisationConfig(context.organisationId).then((response) => this.organisationConfig = response);
  }
  render() {
    const { context } = getSessionDetails();
    const { apiSozluk, language, mentornityBridgeApi, organisationConfig, viewUserDetailDialogActionData } = this;
    const pairSelectionViewConfig = getPairSelectionViewConfig(language, organisationConfig);
    if (!pairSelectionViewConfig) {
      return (h("div", { class: "d-flex justify-content-center pt-3" }, h("dvn-progress", { indefinite: true })));
    }
    return (h(Host, { style: { display: 'block' } }, h("mentornity-root-wrapper", null, h("dvn-app-view-atama-member-pair-selection-view", { apiAtama: mentornityBridgeApi, apiUye: mentornityBridgeApi, notifier: this.notifier, params: getPairSelectionParameters(), view: pairSelectionViewConfig }), viewUserDetailDialogActionData &&
      h("dvn-dialog", { raw: true, shown: true, onDismiss: () => this.viewUserDetailDialogActionData = undefined }, h("dvn-app-view-detail-view-card", { apiSozluk: apiSozluk, apiData: mentornityBridgeApi, id: "user-page", params: getUserDetailDialogParams(viewUserDetailDialogActionData), view: getUserDetailDialogViewConfig(context, organisationConfig) })))));
  }
};
injectNotifier(MentornityPairsOverviewWrapper);

export { MentornityPairsOverviewWrapper as mentornity_pair_selection_wrapper };
