import{r as t,h as s}from"./p-9f21f85f.js";import{T as i}from"./p-968ee2ec.js";import{V as r}from"./p-56463912.js";import"./p-25d382ec.js";import"./p-3968aca6.js";import"./p-d343a062.js";import{g as o,c as e,m as p}from"./p-c44f96b9.js";import{b as a}from"./p-905285ef.js";import{I as n}from"./p-bea38b23.js";import{s as m,h as c,i as d}from"./p-cb585cde.js";import{S as f}from"./p-c2c9e896.js";import"./p-31e77e7b.js";import"./p-105f7627.js";import"./p-35c7f358.js";import"./p-6a6f355f.js";import"./p-aa5ffe14.js";import"./p-293acc32.js";import"./p-f2965a61.js";import"./p-0563ceba.js";import"./p-1e47e7bd.js";import"./p-825ab276.js";import"./p-6c8be41c.js";import"./p-1187cc7c.js";import"./p-881a2bb8.js";import"./p-d27cb594.js";import"./p-9c82afa0.js";import"./p-d6c479ab.js";import"./p-10cfccbb.js";import"./p-8d2ddf16.js";import"./p-814af281.js";import"./p-e929429b.js";import"./p-0988b316.js";import"./p-65eb3f89.js";import"./p-42939000.js";import"./p-a86d8cf2.js";import"./p-3ccedaa0.js";import"./p-9aa2fafd.js";import"./p-3d141e05.js";import"./p-d59ffc5b.js";const h=(t,s,o)=>{let e=[];if(o){const t=s.metadatas[o.target];e=o.form.fields.map((s=>{const i=t.find((t=>t.id===s.id));if(i)return a(i)})).filter((t=>!!t))}return[new i("firstName",t.firstName,"","").setErrorTitle(t.firstName).require(),new i("lastName",t.lastName,"","").setErrorTitle(t.lastName).require(),new i("email",t.email,"","","email").setErrorTitle(t.email).addInterceptor("onSubmit",new r).require(),...e,{id:"mentornityApplicationLegalFooter",customViewTag:"mentornity-application-legal-footer",i18n:t}]},l=class{constructor(s){t(this,s),this.isProgressing=!1,this.isComplete=!1,this.onSubmit=t=>{if(this.onAction)return void this.onAction("submit");const{context:s}=o(),i=t.detail.values;this.isProgressing=!0,this.api.createMembershipApplication(s.organisationId,"mentor"===this.formTarget?"mentors":"mentees",i).then(this.onSucceed,this.onError)},this.onSucceed=()=>{this.isProgressing=!1,this.isComplete=!0},this.onError=t=>{this.error=t,this.isProgressing=!1}}async componentWillLoad(){const{headers:t}=o();this.api=e(p,t);const s=(new f).setLanguage(this.language).setContents(m);this.strings=await s.getContent(c,d);const i=await this.api.getOrganisation(this.organisationId).catch((t=>this.error=t));if(i){if(this.organisation=i,this.configFromEditor)this.organisationConfig=this.configFromEditor;else{const t=await this.api.getOrganisationConfig(i._id).catch((t=>this.error=t));if(!t)return;this.organisationConfig=t}this.formFromEditor?this.form=this.formFromEditor:this.api.getMembershipApplicationForm(i._id,"mentor"===this.formTarget?"mentors":"mentees").then((t=>this.form=t)).catch((t=>this.error=t))}}render(){const{error:t,form:i,formFromEditor:r,organisation:o,organisationConfig:e,isComplete:p,isProgressing:a,strings:m}=this,c=r||i;return!c&&t&&404===t.status?s("mentornity-root-wrapper",{class:"d-flex flex-column align-items-center"},s("p",{class:"p-3"},m.appsAreNotOpen)):c&&o&&m?"unpublished"===c.status?s("mentornity-root-wrapper",{class:"d-flex flex-column align-items-center"},s("p",{class:"p-3"},m.appsAreNotOpen)):s("mentornity-root-wrapper",{class:"d-block p-3"},s("div",{style:{margin:"0 auto",maxWidth:"600px"}},s("dvn-card",{leanedSides:!0},s("dvn-card-header",{title:c.title,slot:"header",showCover:!0,coverSrc:o.coverUrl||"https://bit.ly/36goixD",showImage:!0,imageSrc:o.logoUrl,imageShape:"rounded",imageBorder:!0,imagePosition:n.BelowCover},s("div",{slot:"subtitle"},this.organisation.title)),s("dvn-markdown",{content:c.description})),!p&&s("dvn-card",{leanedSides:!0},s("doldurma-form",{fields:h(m,e,c),onSubmit:this.onSubmit,submitButtonLabel:m.sendApplication,progressing:a||p,formErrors:[]})),p&&s("dvn-card",{leanedSides:!0,tint:"secondary"},m.applicationIsSent),t&&s("dvn-card",{leanedSides:!0,tint:"danger"},m.applicationFailed))):s("mentornity-root-wrapper",null,s("div",{class:"d-flex justify-content-center pt-3"},s("dvn-progress",{indefinite:!0})))}};export{l as mentornity_membership_application_wrapper}