import { getCookieStorage } from '@dvn/kimlik/storage';
import { createMentornityApiInstance } from '../../../mentornity-js-client';
import { mentornityApiEndpoint } from '../constants/env';
export class EditOrganisationConfigFormHandler {
  constructor() {
    const { jwt, sessionId } = getCookieStorage().getAll();
    this.api = createMentornityApiInstance(mentornityApiEndpoint, {
      'Authorization': `Bearer ${jwt}`,
      'Client': 'd2ViLWFkbWlu',
      'Session-Token': sessionId,
    });
  }
  onSubmit(event) {
    const { values } = event.detail;
    const { item, membershipForm, pairOverviewAndDetail } = values;
    return new Promise((resolve, reject) => {
      this.api.update('configs', item._id, {
        webAppConfiguration: {
          membershipForm, pairOverviewAndDetail
        }
      }).then(() => {
        resolve({
          navigation: {
            type: 'navigation',
            direction: 'back'
          }
        });
      }).catch(() => {
        reject(['Unexpected error']);
      });
    });
  }
}
