import{r as t,h as e,H as s}from"./p-9f21f85f.js";import{i as n}from"./p-9315742d.js";import"./p-83f217d4.js";const i=class{constructor(e){t(this,e),this.agreements=[],this.consentedAgreements=[],this.onAgree=async t=>{const e=this.consentedAgreements.some((e=>e._id===t._id));this.consentedAgreements=e?this.consentedAgreements.filter((e=>e._id!==t._id)):[...this.consentedAgreements,t]},this.onSubmit=async()=>{const{consentedAgreements:t}=this;let e=[];for(let s=0;s<t.length;s++)e=[...e,this.apiUye.consentAgreement(t[s]._id)];const s=await Promise.all(e).catch((t=>this.error=t));s&&await this.apiUye.updateMembership(this.membership.config._id,this.membership._id,{consents:s}).catch((t=>this.error=t))&&this.appContextInvalidator()}}componentDidLoad(){const{agreements:t}=this.membership.config;if(!(this.agreements.length>=t.length))for(let e=0;e<t.length;e++)this.apiUye.getAgreement(t[e]._id).then((t=>this.agreements=[...this.agreements,t]),(t=>this.error=t))}render(){var t,n;const{agreements:i,consentedAgreements:o,membership:a}=this,{config:c}=a;return d=i.length!==c.agreements.length?e("div",{class:"col-4 d-flex flex-column justify-content-center align-items-center mt-3"},e("div",{class:"d-flex justify-content-center"},e("dvn-progress",{indefinite:!0}))):e("div",{class:"col-sm-12 col-md-8"},e("div",{class:"d-flex flex-column"},e("dvn-app-space-message-card",{space:a.config.space},a.config.space.name," requires you to read and accept these terms and agreements."),i.map(((t,s)=>{const n=o.some((e=>e._id===t._id));return e("dvn-card",{leaned:s%2==0,leanedSides:!0,elevation:0},e("dvn-card-header",{title:t.title,slot:"header"},e("div",{slot:"action"},e("dvn-button",{onClick:()=>this.selectedAgreement=t,scale:"small",view:"outline"},"Read Agreement"))),e("dvn-checkbox",{leaned:!0,checked:n,label:"I read and accept the terms in the condition",onChange:()=>this.onAgree(t)}))})),e("dvn-button",{fill:!0,disabled:o.length!==i.length,leaned:!0,onClick:()=>this.onSubmit(),tint:"primary"},"Give Consent"),e("dvn-dialog",{title:null===(t=this.selectedAgreement)||void 0===t?void 0:t.title,shown:!!this.selectedAgreement,onDismiss:()=>this.selectedAgreement=void 0},e("dvn-markdown",{content:null===(n=this.selectedAgreement)||void 0===n?void 0:n.content})))),e(s,{class:"row justify-content-center mt-3"},d);var d}};n(i);export{i as dvn_app_membership_consent}