import{r as e,h as t,H as s}from"./p-1ea36ff3.js";import{i}from"./p-fdec3fb2.js";import"./p-fde6bda9.js";import"./p-83f217d4.js";let n=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,i;const{agreements:n,consentedAgreements:o,membership:a}=this,{config:d}=a;return c=n.length!==d.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:a.config.space},a.config.space.name," requires you to read and accept these terms and agreements."),n.map(((e,s)=>{const i=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:i,label:"I read and accept the terms in the condition",onChange:()=>this.onAgree(e)}))})),t("dvn-button",{fill:!0,disabled:o.length!==n.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===(i=this.selectedAgreement)||void 0===i?void 0:i.content})))),t(s,{class:"row justify-content-center mt-3"},c);var c}};i(n);export{n as dvn_app_membership_consent}