import { T as TextField } from './index-d9d18e9c.js';
import { D as DataModel } from './data-model-bb5789f5.js';
import { g as generateFieldModelFromRawData, R as ReferenceField, a as RangeField } from './FieldModelGenerator-755e3a85.js';
import { S as SingleChoiceField } from './index-a95fa2f4.js';
import { M as MembershipConfig } from './membership-config-1607e716.js';
import { U as User } from './User-e14f1ece.js';
import { A as APIBase } from './kimlikApi-81acfec6.js';
import { a as AttachmentField } from './attachment-8831acff.js';
import './index-c43f1f2e.js';

const skills = [
  'academic',
  'accounting',
  'activism',
  'ads',
  'advertising',
  'affiliate-marketing',
  'analytics',
  'apis',
  'ar',
  'art',
  'artificial-intelligence',
  'audit',
  'automotive',
  'b2b',
  'b2c',
  'backend',
  'banking',
  'behavior-change',
  'bidding',
  'big-data',
  'biodiversity',
  'biotechnology',
  'blockchain',
  'blogs',
  'branching',
  'brand',
  'broadcasting',
  'buildings',
  'business',
  'business-administration',
  'business-dev',
  'business-model',
  'business-planning',
  'c2c',
  'chemistry',
  'churn-management',
  'circular-economy',
  'cloud-computing',
  'coding',
  'communications',
  'communities',
  'community-management',
  'construction',
  'content-management',
  'content-marketing',
  'contract-administration',
  'crowdfunding',
  'crowd-sourcing',
  'cryptocurrency',
  'customer-relations',
  'customs',
  'data-science',
  'deep-learning',
  'defense-industry',
  'delivery-services',
  'demodays',
  'design',
  'design-thinking',
  'diabetes',
  'diagnostics',
  'digital-marketing',
  'distribution',
  'drip-marketing',
  'drones',
  'dropshipping',
  'earth-observation',
  'e-commerce',
  'edtech',
  'education',
  'e-learning',
  'electric-cars',
  'elevator-pitch',
  'email-marketing',
  'emea',
  'employee-engagement',
  'energy',
  'entrepreneurship',
  'esports',
  'estate',
  'eu',
  'event-management',
  'executive-coaching',
  'finance',
  'fintech',
  'fmcg',
  'food',
  'foreign-trade',
  'franchising',
  'frontend',
  'funding',
  'fundraising-strategy',
  'game-development',
  'gdpr',
  'gov-relations',
  'grants',
  'graphic-design',
  'growth-hacking',
  'hardware',
  'health',
  'human-resources',
  'ico',
  'idea-proof',
  'indiegogo',
  'innovation',
  'insurance',
  'insuretech',
  'international-sales',
  'investor-relations',
  'iot',
  'ipo',
  'it',
  'kickstarter',
  'landing-pages',
  'law',
  'leadership',
  'lead-generation',
  'lean-startup',
  'life-sciences',
  'machine-learning',
  'management-consulting',
  'marketing',
  'marketing-automations',
  'marketplace',
  'market-research',
  'materials',
  'materials-science',
  'medicine',
  'medtech',
  'mena',
  'mindfulness',
  'mobile-development',
  'motivation',
  'nanotechnology',
  'networking',
  'nutrition',
  'online-games',
  'open-source',
  'organic-foods',
  'organizational-development',
  'patent',
  'payment-systems',
  'pitch-decks',
  'pitching',
  'planning',
  'politics',
  'presentation-design',
  'presentation-skills',
  'press',
  'pricing',
  'privacy',
  'procurement',
  'prod',
  'prod-dev',
  'professional-coaching',
  'project-management',
  'psychology',
  'public-relations',
  'publishing',
  'purchasing',
  'quality',
  'recruitment',
  'renewables',
  'reseller-management',
  'resilience',
  'robotics',
  'saas',
  'sales',
  'satellite-navigation',
  'search-engines',
  'sea-technologies',
  'security',
  'sem',
  'service-design',
  'sharing-economy',
  'shipping',
  'silicon-valley',
  'smart-cities',
  'social-entrepreneurship',
  'social-media',
  'soft-skills',
  'software',
  'software-dev',
  'solar-power',
  'space-tech',
  'sports',
  'statistics',
  'storytelling',
  'strategy',
  'supply-chain',
  'sustainability',
  'talent-management',
  'taxes',
  'team-management',
  'tech',
  'telecom',
  'time-management',
  'tourism',
  'transport',
  'travel',
  'ui',
  'unit-economics',
  'ux',
  'ux-design',
  'ux-research',
  'vc',
  'vegan-foods',
  'viral-marketing',
  'virology',
  'vr',
  'waste',
  'water',
  'wind-power',
  'youtube',
];

const skillsEN = {
  analytics: 'Analytics',
  business: 'Business',
  chemistry: 'Chemistry',
  'data-science': 'Data Science',
  'design-thinking': 'Design Thinking',
  diabetes: 'Diabetes',
  diagnostics: 'Diagnostics',
  'graphic-design': 'Graphic Design',
  'life-sciences': 'Life sciences',
  medicine: 'Medicine',
  medtech: 'Medtech',
  pitching: 'Pitching',
  'presentation-design': 'Presentation Design',
  'service-design': 'Service Design',
  'ux-design': 'UX design',
  'ux-research': 'UX research',
  virology: 'Virology',
  academic: 'Academic',
  accounting: 'Accounting',
  activism: 'Activism',
  ads: 'Ads',
  advertising: 'Advertising',
  'affiliate-marketing': 'Affiliate Marketing',
  apis: 'APIs',
  ar: 'AR Augmented Reality',
  art: 'Art',
  'artificial-intelligence': 'Ai Artificial Intelligence',
  audit: 'Audit',
  automotive: 'Automotive',
  b2b: 'B2B',
  b2c: 'B2C',
  backend: 'Backend',
  banking: 'Banking',
  'behavior-change': 'Behavior Change',
  bidding: 'Bidding',
  'big-data': 'Big Data',
  biodiversity: 'Biodiversity',
  biotechnology: 'Biotechnology',
  blockchain: 'Blockchain',
  blogs: 'Blogs',
  branching: 'Branching',
  brand: 'Brand',
  broadcasting: 'Broadcasting',
  buildings: 'Buildings',
  'business-administration': 'Business Administration',
  'business-dev': 'Business Development',
  'business-model': 'Business Model',
  'business-planning': 'Business Planning',
  c2c: 'C2C',
  'churn-management': 'Churn Management',
  'circular-economy': 'Circular Economy',
  'cloud-computing': 'Cloud Computing',
  coding: 'Coding',
  communications: 'Communications',
  communities: 'Communities',
  'community-management': 'Community Management',
  construction: 'Construction',
  'content-management': 'Content Management',
  'content-marketing': 'Content Marketing',
  'contract-administration': 'Contract Administration',
  crowdfunding: 'CrowdFunding',
  'crowd-sourcing': 'Crowd Sourcing',
  cryptocurrency: 'CryptoCurrency',
  'customer-relations': 'Customer Relations',
  customs: 'Customs',
  'deep-learning': 'Deep Learning',
  'defense-industry': 'Defense Industry',
  'delivery-services': 'Delivery Services',
  demodays: 'Demodays',
  design: 'Design',
  'digital-marketing': 'Digital Marketing',
  distribution: 'Distribution',
  'drip-marketing': 'Drip Marketing',
  drones: 'Drones',
  dropshipping: 'Dropshipping',
  'earth-observation': 'Earth Observation',
  'e-commerce': 'E-Commerce',
  edtech: 'EdTech',
  education: 'Education',
  'e-learning': 'E-Learning',
  'electric-cars': 'Electric Cars',
  'elevator-pitch': 'Elevator Pitch',
  'email-marketing': 'Email Marketing',
  emea: 'EMEA Region',
  'employee-engagement': 'Employee Engagement',
  energy: 'Energy',
  entrepreneurship: 'Entrepreneurship',
  esports: 'ESports',
  estate: 'Estate',
  eu: 'EU European Union',
  'event-management': 'Event Management',
  'executive-coaching': 'Executive Coaching',
  finance: 'Finance',
  fintech: 'FinTech',
  fmcg: 'FMCG',
  food: 'Food',
  'foreign-trade': 'Foreign Trade',
  franchising: 'Franchising',
  frontend: 'Frontend',
  funding: 'Funding',
  'fundraising-strategy': 'Fundraising Strategy',
  'game-development': 'Game Development',
  gdpr: 'GDPR',
  'gov-relations': 'Government Relations',
  grants: 'Grants',
  'growth-hacking': 'Growth Hacking',
  hardware: 'Hardware',
  health: 'Health',
  'human-resources': 'HR Human Resources',
  ico: 'ICO',
  'idea-proof': 'Idea Proof',
  indiegogo: 'Indiegogo',
  innovation: 'Innovation',
  insurance: 'Insurance',
  insuretech: 'InsureTech',
  'international-sales': 'International Sales',
  'investor-relations': 'Investor Relations',
  iot: 'IoT',
  ipo: 'IPO',
  it: 'IT',
  kickstarter: 'Kickstarter',
  'landing-pages': 'Landing Pages',
  law: 'Law',
  leadership: 'Leadership',
  'lead-generation': 'Lead Generation',
  'lean-startup': 'Lean Startup',
  'machine-learning': 'Machine Learning',
  'management-consulting': 'Management Consulting',
  marketing: 'Marketing',
  'marketing-automations': 'Marketing Automations',
  marketplace: 'Marketplace',
  'market-research': 'Market Research',
  materials: 'Materials',
  'materials-science': 'Materials Science',
  mena: 'MENA Region',
  mindfulness: 'Mindfulness',
  'mobile-development': 'Mobile Development',
  motivation: 'Motivation',
  nanotechnology: 'Nanotechnology',
  networking: 'Networking',
  nutrition: 'Nutrition',
  'online-games': 'Online Games',
  'open-source': 'Open Source',
  'organic-foods': 'Organic Foods',
  'organizational-development': 'Organizational Development',
  patent: 'Patent',
  'payment-systems': 'Payment Systems',
  'pitch-decks': 'Pitch Decks',
  planning: 'Planning',
  politics: 'Politics',
  'presentation-skills': 'Presentation Skills',
  press: 'Press',
  pricing: 'Pricing',
  privacy: 'Privacy',
  procurement: 'Procurement',
  prod: 'Product',
  'prod-dev': 'Product Development',
  'professional-coaching': 'Professional Coaching',
  'project-management': 'Project Management',
  psychology: 'Psychology',
  'public-relations': 'PR Public Relations',
  publishing: 'Publishing',
  purchasing: 'Purchasing ',
  quality: 'Quality',
  recruitment: 'Recruitment',
  renewables: 'Renewables',
  'reseller-management': 'Reseller Management',
  resilience: 'Resilience',
  robotics: 'Robotics',
  saas: 'SaaS',
  sales: 'Sales',
  'satellite-navigation': 'Satellite Navigation',
  'search-engines': 'Search Engines',
  'sea-technologies': 'Sea Technologies',
  security: 'Security',
  sem: 'SEM Serch Engine Marketing',
  'sharing-economy': 'Sharing Economy',
  shipping: 'Shipping',
  'silicon-valley': 'Silicon Valley',
  'smart-cities': 'Smart Cities',
  'social-entrepreneurship': 'Social Entrepreneurship',
  'social-media': 'Social media',
  'soft-skills': 'Soft Skills',
  software: 'Software',
  'software-dev': 'Software Development',
  'solar-power': 'Solar Power',
  'space-tech': 'Space Tech',
  sports: 'Sports',
  statistics: 'Statistics',
  storytelling: 'Storytelling',
  strategy: 'Strategy',
  'supply-chain': 'Supply Chain',
  sustainability: 'Sustainability',
  'talent-management': 'Talent Management',
  taxes: 'Taxes',
  'team-management': 'Team Management',
  tech: 'Tech',
  telecom: 'Telecom',
  'time-management': 'Time Management',
  tourism: 'Tourism',
  transport: 'Transport',
  travel: 'Travel',
  ui: 'UI',
  'unit-economics': 'Unit Economics',
  ux: 'UX',
  vc: 'VC Venture Capitals',
  'vegan-foods': 'Vegan foods',
  'viral-marketing': 'Viral Marketing',
  vr: 'VR Virtual Reality',
  waste: 'Waste',
  water: 'Water',
  'wind-power': 'Wind Power',
  youtube: 'Youtube',
};

var __rest = (undefined && undefined.__rest) || function (s, e) {
  var t = {};
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
    t[p] = s[p];
  if (s != null && typeof Object.getOwnPropertySymbols === "function")
    for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
      if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
        t[p[i]] = s[p[i]];
    }
  return t;
};
function getRequestStatus(request) {
  if (request.status === 'completed') {
    return 'completed';
  }
  if (request.rejectedAt) {
    return 'rejected';
  }
  else if (request.canceledAt) {
    return 'canceled';
  }
  else if (request.acceptedAt) {
    return 'accepted';
  }
  else if (request.requestedAt) {
    return 'requested';
  }
}
const commonUserInfoFields = [
  generateFieldModelFromRawData({ id: 'fullName', type: 'text' }),
  generateFieldModelFromRawData({ id: 'imageUrl', type: 'image' }),
  generateFieldModelFromRawData({ id: 'title', title: 'Title', type: 'text' }),
  generateFieldModelFromRawData({ id: 'bio', title: 'Bio', type: 'text', lines: 3 }),
  generateFieldModelFromRawData({ id: 'imagePlaceholderValue', title: '', type: 'text' }),
  generateFieldModelFromRawData({
    id: 'skills',
    title: 'Professional Expertise',
    type: 'multipleChoice',
    inputType: 'tag-cloud',
    options: skills.map(skill => ({
      label: skillsEN[skill], value: skill,
    })),
  }),
];
const groupInfoFields = [
  generateFieldModelFromRawData({ id: 'imageUrl', type: 'image' }),
  generateFieldModelFromRawData({ id: 'title', title: 'Title', type: 'text' }),
  generateFieldModelFromRawData({ id: 'description', title: 'Description', type: 'text', lines: 3 }),
  generateFieldModelFromRawData({ id: 'imagePlaceholderValue', title: '', type: 'text' }),
  new ReferenceField('members', 'Members', 'fullName', 'imageUrl', 'users', [
    new AttachmentField('imageUrl', ''),
    new TextField('firstName', 'First Name'),
    new TextField('lastName', 'Last Name'),
    new TextField('fullName', 'Last Name'),
  ], false),
];
function convertMentornityFieldToDevingenField(field) {
  if (field.type === 'ratingStars') {
    return new RangeField(field.id, field.title, field.description, 0.2, 0.2, 1).setInputType('stars');
  }
  else if (field.type === 'singleChoice') {
    return new SingleChoiceField(field.id, field.title, field.options, field.description, field.inputType, field.placeholder);
  }
  return generateFieldModelFromRawData(field);
}
class MentornityBridgeApi {
  constructor(endpoint, context, headers) {
    this.client = new APIBase(endpoint, headers);
    this.context = context;
  }
  addAuthInterceptor(_token) {
    // console.log('MBA.addAuthInterceptor', token);
  }
  // DATA API
  get(collection, id, _query) {
    // console.log('MBA.get', collection, id, _query);
    const { organisationId } = this.context;
    if (collection === 'groups') {
      return new Promise((resolve => {
        this.client.get(`groups/${id}`).then(response => {
          resolve(DataModel.decode(Object.assign(Object.assign({ 
            // dvn-app-view-atama-member-pair-detail-view expects 'user' field in the 'membership' object
            user: {
              // id is needed here because the user object is sent to web-client when create meeting is clicked
              _id: response._id,
              firstName: response.title,
              lastName: ' ',
            } }, response), { members: (response.members || []).map(member => (Object.assign(Object.assign({}, member), { fullName: `${member.firstName} ${member.lastName}` }))) })));
        }).catch(_e => {
          // console.log(e);
        });
      }));
    }
    return new Promise((resolve => {
      this.client.get(`organisations/${organisationId}/${collection}/${id}`).then(response => {
        var _a;
        // separate metadata and user data. consider title, bio and skills as metadata
        const { metadata, title, bio, skills } = response, rest = __rest(response, ["metadata", "title", "bio", "skills"]);
        resolve(DataModel.decode(Object.assign(Object.assign({ user: User.decode(rest) }, (((_a = response.metadata) === null || _a === void 0 ? void 0 : _a.data) || {})), { title, bio, skills })));
      }).catch(_e => {
        // console.log(e);
      });
    }));
  }
  query(collection, query) {
    if (['mentees', 'mentors'].includes(collection)) {
      // this request is called by dvn-app-view-detail-view that is opened
      // when mentor clicks on the mentee info inside the received requests list
      const { organisationId } = this.context;
      const menteeId = query.filter.value;
      return new Promise((resolve => {
        this.client.get(`organisations/${organisationId}/${collection}/${menteeId}`).then(response => {
          var _a;
          // separate metadata and user data. consider title, bio and skills as metadata
          const { metadata, title, bio, skills } = response, rest = __rest(response, ["metadata", "title", "bio", "skills"]);
          resolve({
            results: [
              DataModel.decode(Object.assign(Object.assign({ fullName: `${response.firstName} ${response.lastName}`, user: User.decode(rest) }, (((_a = response.metadata) === null || _a === void 0 ? void 0 : _a.data) || {})), { title, bio, skills }))
            ]
          });
        }).catch(e => {
          console.log(e);
        });
      }));
    }
    return Promise.resolve(undefined);
  }
  update(_collection, _id, _body) {
    return Promise.reject({ status: 418 });
  }
  // ATAMA API
  getPairsOfUser(_base, _collection, userRefFieldId, _userRefFieldValue) {
    // console.log('MBA.getPairsOfUser', base, collection, userRefFieldId, userRefFieldValue);
    const { organisationId } = this.context;
    const { menteeType } = this.organisationConfig;
    // if user reference field is subscribed, then it's a mentor viewing its mentees
    const listToFetch = userRefFieldId === 'subscribed'
      ? (menteeType === 'group' ? 'groups' : 'mentees')
      : 'mentors';
    const itemNameToReturn = userRefFieldId === 'subscribed' ? 'subscriber' : 'subscribed';
    const params = listToFetch === 'groups'
      ? { expandCreatedBy: false }
      : { expandMetadatas: true, appendSubscription: true, };
    return new Promise((resolve => {
      this.client.get(`organisations/${organisationId}/${listToFetch}`, params).then(response => {
        // console.log('response', response);
        setTimeout(() => resolve({
          results: response.results
            // show only the active pairs
            .filter(item => item.subscription.status === 'active')
            .map(item => {
            var _a;
            return ({
              [itemNameToReturn]: [Object.assign(Object.assign(Object.assign({}, item), (((_a = item.metadata) === null || _a === void 0 ? void 0 : _a.data) || {})), { fullName: `${item.firstName} ${item.lastName}`, imagePlaceholderValue: listToFetch === 'groups'
                    ? ((item.title && item.title.length > 0) ? item.title[0] : '')
                    : `${item.firstName[0]} ${item.lastName[0]}` })],
              status: item.subscription.status,
            });
          }),
          meta: response.meta,
        }), 100);
      }).catch(_e => {
        // console.log(e);
      });
    }));
  }
  getSelectionList(_base, _collection, _pairConfigId, _userRefFieldId, _memberToViewRefFieldId) {
    // console.log('MBA.getSelectionList', base, collection, pairConfigId, userRefFieldId, memberToViewRefFieldId);
    const { organisationId } = this.context;
    return new Promise(resolve => {
      this.client.get(`organisations/${organisationId}/mentors/selection`).then(response => resolve({
        results: response.results.map(item => {
          var _a;
          return (Object.assign(Object.assign(Object.assign({}, item), (((_a = item.metadata) === null || _a === void 0 ? void 0 : _a.data) || {})), { fullName: `${item.firstName} ${item.lastName}` }));
        })
      })).catch(_e => {
        // console.log(e);
      });
    });
  }
  getSentRequests(_base, _collection, _userRefFieldValue) {
    // console.log('MBA.getSentRequests', base, collection, userRefFieldValue);
    const { organisationId } = this.context;
    return new Promise((resolve => {
      this.client.get(`organisations/${organisationId}/mentors`, { appendRequestSubscriptions: true, limit: 1000 }).then(response => {
        // console.log('response', response);
        setTimeout(() => resolve({
          results: response.results
            // subscription must contain 'requestedAt' field if this subscription is created via selection request
            .filter(item => !!item.subscription.requestedAt)
            .map(item => ({
            sentTo: User.decode(item),
            status: getRequestStatus(item.subscription),
            requestedAt: item.subscription.requestedAt,
            acceptedAt: item.subscription.acceptedAt,
            rejectedAt: item.subscription.rejectedAt,
            canceledAt: item.subscription.canceledAt,
          })),
          meta: response.meta,
        }), 100);
      }).catch(_e => {
        // console.log(e);
      });
    }));
  }
  getReceivedRequests(_base, _collection) {
    // console.log('MBA.getReceivedRequests', base, collection);
    const { organisationId } = this.context;
    return new Promise((resolve => {
      this.client.get(`organisations/${organisationId}/mentees`, { expandMetadatas: true, limit: 1000 }).then(response => {
        setTimeout(() => resolve({
          results: response.results
            // subscription must contain 'requestedAt' field if this subscription is created via selection request
            .filter(item => !!item.subscription.requestedAt)
            // show only pending requests
            .sort((a, b) => b.subscription.createdAt - a.subscription.createdAt)
            .map(item => ({
            _id: item.subscription._id,
            sentBy: User.decode(item),
            status: getRequestStatus(item.subscription),
            requestedAt: item.subscription.requestedAt,
            acceptedAt: item.subscription.acceptedAt,
            rejectedAt: item.subscription.rejectedAt,
            canceledAt: item.subscription.canceledAt,
          })),
          meta: response.meta,
        }), 100);
      }).catch(_e => {
        // console.log(e);
      });
    }));
  }
  sendPairRequest(_base, _collection, _userRefFieldId, userRefFieldValue, _memberToViewRefFieldId, memberToViewData) {
    // console.log('MBA.endPair', base, collection, pairId);
    const { organisationId } = this.context;
    const subscription = {
      mentorship: { _type: 'reference', _class: 'mentorships', _id: memberToViewData.mentorship._id },
      organisation: { _type: 'reference', _class: 'organisations', _id: organisationId },
      subscribed: { _type: 'reference', _class: 'users', _id: memberToViewData._id },
      subscriber: { _type: 'reference', _class: 'users', _id: userRefFieldValue },
      status: 'requested',
    };
    return this.client.post(`subscriptions`, subscription);
    // return Promise.reject({ status: 409 });
  }
  acceptPairRequest(_base, _collection, requestId) {
    return this.client.post(`subscriptions/${requestId}/accept`, {});
  }
  rejectPairRequest(_base, _collection, requestId) {
    return this.client.post(`subscriptions/${requestId}/reject`, {});
  }
  getMeetingsOfUser(_base, _collection, _structureId, _userRefFieldValue) {
    // console.log('MBA.getMeetingsOfUser', base, collection, structureId, userRefFieldValue);
    // the response contains all the meetings with different users
    // here we filter the events based on the user id we're viewing
    const userIdToView = new URLSearchParams(window.location.search).get('uid');
    return new Promise((async (resolve) => {
      const response = await this.client.get(`organisations/${this.context.organisationDomain}/meetingsInMeetingGoal`);
      resolve({
        results: response.results.filter(meeting => meeting.guests.some(guest => guest._id === userIdToView))
      });
    }));
  }
  endPair(_base, _collection, pairId) {
    // console.log('MBA.endPair', base, collection, pairId);
    return new Promise((async (resolve) => {
      const response = await this.client.post(`subscriptions/${pairId}/complete`, {});
      resolve(response);
    }));
  }
  // UYE API
  getAppConfigOfMembership(_id) {
    // console.log('MBA.getAppConfigOfMembership', id);
    return Promise.reject({ status: 418 });
  }
  consentAgreement(_id) {
    // console.log('MBA.consentAgreement', id);
    return Promise.reject({ status: 418 });
  }
  getAgreement(_id) {
    // console.log('MBA.getAgreement', id);
    return Promise.reject({ status: 418 });
  }
  activateMembership(_membershipConfigId, _membershipId) {
    // console.log('MBA.getMembership', id);
    return Promise.reject({ status: 418 });
  }
  getMembership(_membershipConfigId, _membershipId) {
    // console.log('MBA.getMembership', id);
    return Promise.reject({ status: 418 });
  }
  getMembershipsOfUser(_userId) {
    // console.log('MBA.getMembershipsOfUser', userId);
    return Promise.reject({ status: 418 });
  }
  // getMembershipConfig(_id: string): Promise<MembershipConfig> {
  //   console.log('MBA.getMembershipConfig', id);
  // return Promise.reject({ status: 418 });
  // }
  getMembershipConfigWithName(name) {
    // console.log('MBA.getMembershipConfigWithName', name);
    const { organisationId } = this.context;
    return new Promise((async (resolve) => {
      this.client.get(`organisations/${organisationId}/config`).then(organisationConfig => {
        this.organisationConfig = organisationConfig;
        let fields = [];
        let roleName = '';
        if (name === 'mentees') {
          roleName = 'mentee';
          fields = [
            ...commonUserInfoFields,
            ...organisationConfig.metadatas.mentee
              .map(convertMentornityFieldToDevingenField),
          ];
        }
        else if (name === 'mentors') {
          roleName = 'mentor';
          fields = [
            ...commonUserInfoFields,
            ...organisationConfig.metadatas.mentor
              .map(convertMentornityFieldToDevingenField),
          ];
        }
        else if (name === 'groups') {
          roleName = 'mentee';
          fields = [
            ...groupInfoFields,
          ];
        }
        resolve(MembershipConfig.decode({
          roleName,
          fields,
        }));
      }).catch(_e => {
        // console.log(e);
      });
    }));
  }
  updateMembership(_membershipConfigId, _membershipId, _data) {
    // console.log('MBA.updateMembership', id, data);
    return Promise.reject({ status: 418 });
  }
}

function convertFieldsToFieldReferences(fields) {
  return fields.map(field => ({ fieldId: field.id }));
}
function getFieldsToShow(role, config) {
  // show the mentee fields if the user role is mentor. otherwise show mentor fields
  return (role === 'mentor' ? config.metadatas.mentee : config.metadatas.mentor) || [];
}
function getPairConfigOptionsFromOrganisationConfig(config) {
  const { subscriptionConfig } = config;
  return {
    isMentorSelectionOn: subscriptionConfig.mentorVisibilityStatus === 'showAvailableMentors',
    canMentorEndSubscription: subscriptionConfig.mentorsCanEndSubscription,
    pairLimitForMentees: config.subscriptionConfig.menteeSubscriptionLimit,
    selectionLimitForMentees: config.subscriptionConfig.menteeSelectionLimit,
  };
}

export { MentornityBridgeApi as M, skillsEN as a, convertFieldsToFieldReferences as b, convertMentornityFieldToDevingenField as c, getPairConfigOptionsFromOrganisationConfig as d, commonUserInfoFields as e, getFieldsToShow as g, skills as s };
