'use strict';

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

const index = require('./index-7cdf1df1.js');
const index$1 = require('./index-c2a077ae.js');
require('./InterceptorHandler-09a1e84b.js');
require('./BaseField-f50bb8f0.js');
require('./FieldModelGenerator-5a321a60.js');
require('./date-8e8ca89a.js');
require('./index-e79eb186.js');
require('./_commonjsHelpers-206db00d.js');
require('./index-13fb62eb.js');
require('./kimlikApi-6a581864.js');
require('./data-transfer-field-025bce2f.js');
require('./filter-52876f3c.js');
require('./cookie-8a49bf23.js');
const ValidatorEmail = require('./ValidatorEmail-4449f08a.js');
const instance = require('./instance-adc7fc02.js');
const session = require('./session-a266bfc2.js');

const en = {
  applicationIsSent: 'Your application is sent.',
  applicationFailed: 'Sending the application failed.',
  firstName: 'First name',
  lastName: 'Last name',
  email: 'Email',
  sendApplication: 'Send Application',
};
const tr = {
  applicationIsSent: 'Başvurunuz gönderildi.',
  applicationFailed: 'Başvuru gönderilirken hata oluştu.',
  firstName: 'İsim',
  lastName: 'Soyisim',
  email: 'E-posta',
  sendApplication: 'Başvuruyu Gönder',
};

const formFields = (i18n) => ([
  new index$1.TextField('firstName', '', i18n.firstName, '').setErrorTitle(i18n.firstName)
    .require(),
  new index$1.TextField('lastName', '', i18n.lastName, '').setErrorTitle(i18n.lastName)
    .require(),
  new index$1.TextField('email', '', i18n.email, '', 'email').setErrorTitle(i18n.email)
    .addInterceptor('onSubmit', new ValidatorEmail.ValidatorEmail())
    .require(),
]);
const MentornityMembershipApplicationWrapper = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.isProgressing = false;
    this.isComplete = false;
    this.onSubmit = (event) => {
      const { context } = session.getSessionDetails();
      const data = event.detail.values;
      this.isProgressing = true;
      this.api.createMembershipApplication(context.organisationId, this.role, data).then(this.onSucceed, this.onError);
    };
    this.onSucceed = () => {
      this.isProgressing = false;
      this.isComplete = true;
    };
    this.onError = (error) => {
      this.error = error;
      this.isProgressing = false;
    };
  }
  componentWillLoad() {
    const { context, headers } = session.getSessionDetails();
    this.api = instance.createMentornityApiInstance(session.mentornityApiEndpoint, headers);
    this.api.getOrganisation(context.organisationId).then((response) => {
      this.organisation = response;
    });
    this.api.getMembershipApplicationForm(context.organisationId, this.role).then((response) => {
      this.form = response;
    });
  }
  render() {
    const { error, form, language, organisation, isComplete, isProgressing } = this;
    const i18n = language === 'tr' ? tr : en;
    if (!form || !organisation) {
      return (index.h("mentornity-root-wrapper", null, index.h("div", { class: "d-flex justify-content-center pt-3" }, index.h("dvn-progress", { indefinite: true }))));
    }
    return (index.h("mentornity-root-wrapper", { class: "d-flex flex-column align-items-center" }, index.h("div", { style: { width: '288px' } }, index.h("dvn-card", { leanedSides: true }, index.h("dvn-card-header", { title: form.title, slot: "header", showCover: true, coverBrightness: 50, coverSrc: organisation.coverUrl || 'https://bit.ly/36goixD', showImage: true, imageSrc: organisation.logoUrl, imageShape: "rounded", imageBorder: true }), index.h("dvn-markdown", { content: form.description })), index.h("dvn-card", { leanedSides: true }, index.h("doldurma-form", { fields: formFields(i18n), onSubmit: this.onSubmit, submitButtonLabel: i18n.sendApplication, progressing: isProgressing || isComplete, formErrors: [] })), isComplete &&
      index.h("dvn-card", { leanedSides: true, tint: "secondary" }, i18n.applicationIsSent), error &&
      index.h("dvn-card", { leanedSides: true, tint: "danger" }, i18n.applicationFailed))));
  }
};

exports.mentornity_membership_application_wrapper = MentornityMembershipApplicationWrapper;
