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