import { r as registerInstance, h } from './index-b6f10a81.js';
import { T as TextField } from './index-ec7dc2ad.js';
import './InterceptorHandler-6474bcf4.js';
import './BaseField-d94c5b14.js';
import './FieldModelGenerator-6ec60042.js';
import './date-b270be76.js';
import './index-94c1d7bf.js';
import './_commonjsHelpers-63c253cd.js';
import './index-fd2b14ae.js';
import './kimlikApi-81acfec6.js';
import './data-transfer-field-1ad95e08.js';
import './filter-cbaa3d7d.js';
import './cookie-d9098150.js';
import { V as ValidatorEmail } from './ValidatorEmail-df7a1b77.js';
import { c as createMentornityApiInstance } from './instance-f50cdfd9.js';
import { g as getSessionDetails, m as mentornityApiEndpoint } from './session-78c3c986.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 TextField('firstName', '', i18n.firstName, '').setErrorTitle(i18n.firstName)
    .require(),
  new TextField('lastName', '', i18n.lastName, '').setErrorTitle(i18n.lastName)
    .require(),
  new TextField('email', '', i18n.email, '', 'email').setErrorTitle(i18n.email)
    .addInterceptor('onSubmit', new ValidatorEmail())
    .require(),
]);
const MentornityMembershipApplicationWrapper = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.isProgressing = false;
    this.isComplete = false;
    this.onSubmit = (event) => {
      const { context } = 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 } = getSessionDetails();
    this.api = createMentornityApiInstance(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 (h("mentornity-root-wrapper", null, h("div", { class: "d-flex justify-content-center pt-3" }, h("dvn-progress", { indefinite: true }))));
    }
    return (h("mentornity-root-wrapper", { class: "d-flex flex-column align-items-center" }, h("div", { style: { width: '288px' } }, h("dvn-card", { leanedSides: true }, 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 }), h("dvn-markdown", { content: form.description })), h("dvn-card", { leanedSides: true }, h("doldurma-form", { fields: formFields(i18n), onSubmit: this.onSubmit, submitButtonLabel: i18n.sendApplication, progressing: isProgressing || isComplete, formErrors: [] })), isComplete &&
      h("dvn-card", { leanedSides: true, tint: "secondary" }, i18n.applicationIsSent), error &&
      h("dvn-card", { leanedSides: true, tint: "danger" }, i18n.applicationFailed))));
  }
};

export { MentornityMembershipApplicationWrapper as mentornity_membership_application_wrapper };
