import{r as t,h as i}from"./p-9f21f85f.js";import{I as s}from"./p-bea38b23.js";import{B as o}from"./p-04501405.js";import{T as r}from"./p-968ee2ec.js";import{V as a}from"./p-ad6da9fe.js";import{C as n}from"./p-10cfccbb.js";import{S as e}from"./p-c2c9e896.js";import{M as m,m as h}from"./p-d59ffc5b.js";import"./p-31e77e7b.js";import"./p-105f7627.js";import"./p-35c7f358.js";import"./p-8d2ddf16.js";import"./p-25d382ec.js";import"./p-3968aca6.js";import"./p-d343a062.js";import"./p-814af281.js";const c=class{constructor(i){t(this,i),this.isProgressing=!1,this.formFields=()=>{var t,i,s;const n=(null===(t=this.wl)||void 0===t?void 0:t.termsUrl)||"/terms",m=(null===(i=this.wl)||void 0===i?void 0:i.privacyUrl)||"/privacy-policy",h=(null===(s=this.wl)||void 0===s?void 0:s.domain)||"mentornity.com",c=[new r("email",this.strings.email,this.invitation.issuedFor,"").setErrorTitle(this.strings.email).disable(),new o("constent","","",e.build(this.strings.agreeTermsAndPrivacy,{organisationTermsLink:`https://${h}/terms/${this.organisation._id}/organisation`,organisationTitle:this.organisation.title,policyLink:m,mentornityTerms:n,userAgreement:"https://mentornity.com/kullanici-sozlesmesi",kvkkPolitikasi:"https://tr.mentornity.com/kvkk-politikasi.pdf",kvkkAydinlatmaMetni:"https://tr.mentornity.com/kvkk-aydinlatma-metni.pdf"})).setLabelType("markdown").require()];return this.isLoggedIn||c.splice(1,0,new r("password",this.strings.password,this.strings.definePassword,"","password").setAutoComplete("off").setErrorTitle(this.strings.password).addInterceptor("onSubmit",new a(6,24)).require()),c},this.login=async(t,i)=>{try{const s=await this.api.login(t,i,"web-client");this.storage=new n,this.storage.save("mt_uid",s.user._id),this.storage.save("mt_st",s._id),this.storage.save("mt_at",s.accessToken)}catch(t){this.formErrors=t}},this.saveConsentForPolicy=async()=>{const t=`/${this.organisation.domain}/welcome`,i=this.storage.get("mt_at"),s=this.storage.get("mt_st");this.api.addAuthInterceptor(i,s);try{const i=await this.api.getPrivacyPolicy(this.language||"en");await this.api.saveConsentForPolicy(this.invitation.invitee._id,i._id,"invitation"),window.location=t}catch(t){this.formErrors=t}},this.onSubmit=async t=>{const{values:{constent:i,password:s}}=t.detail;if(this.formErrors=void 0,this.isProgressing=!0,i&&(s||this.isLoggedIn))try{await this.api.acceptInvitation(this.invitation._id,s),this.isLoggedIn?window.location=`/${this.organisation.domain}/welcome`:(await this.login(this.invitation.issuedFor,s),this.saveConsentForPolicy())}catch(t){this.formErrors=t}this.isProgressing=!1}}async componentWillLoad(){this.strings=await this.apiSozluk.getContent(m,h),this.wl=await this.api.getWhiteLabel(this.invitation.organisation._id)}render(){const{organisation:t,formErrors:o,strings:r,isProgressing:a}=this;return i("div",{style:{margin:"0 auto",maxWidth:"600px"}},i("dvn-card",{leanedSides:!0},i("dvn-card-header",{title:r.invitation,slot:"header",showCover:!0,coverSrc:t.coverUrl||"https://bit.ly/36goixD",showImage:!0,imageSrc:t.logoUrl,imageShape:"rounded",imageBorder:!0,imagePosition:s.BelowCover},i("div",{slot:"subtitle"},t.title)),i("dvn-markdown",{content:t.description})),i("dvn-card",{leanedSides:!0},i("doldurma-form",{fields:this.formFields(),onSubmit:this.onSubmit,submitButtonLabel:r.submit,progressing:a,formErrors:o})))}};export{c as mentornity_accept_invitation_widget}