var __awaiter=this&&this.__awaiter||function(e,t,n,r){function i(e){return e instanceof n?e:new n((function(t){t(e)}))}return new(n||(n=Promise))((function(n,s){function o(e){try{c(r.next(e))}catch(e){s(e)}}function a(e){try{c(r["throw"](e))}catch(e){s(e)}}function c(e){e.done?n(e.value):i(e.value).then(o,a)}c((r=r.apply(e,t||[])).next())}))};var __generator=this&&this.__generator||function(e,t){var n={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},r,i,s,o;return o={next:a(0),throw:a(1),return:a(2)},typeof Symbol==="function"&&(o[Symbol.iterator]=function(){return this}),o;function a(e){return function(t){return c([e,t])}}function c(o){if(r)throw new TypeError("Generator is already executing.");while(n)try{if(r=1,i&&(s=o[0]&2?i["return"]:o[0]?i["throw"]||((s=i["return"])&&s.call(i),0):i.next)&&!(s=s.call(i,o[1])).done)return s;if(i=0,s)o=[o[0]&2,s.value];switch(o[0]){case 0:case 1:s=o;break;case 4:n.label++;return{value:o[1],done:false};case 5:n.label++;i=o[1];o=[0];continue;case 7:o=n.ops.pop();n.trys.pop();continue;default:if(!(s=n.trys,s=s.length>0&&s[s.length-1])&&(o[0]===6||o[0]===2)){n=0;continue}if(o[0]===3&&(!s||o[1]>s[0]&&o[1]<s[3])){n.label=o[1];break}if(o[0]===6&&n.label<s[1]){n.label=s[1];s=o;break}if(s&&n.label<s[2]){n.label=s[2];n.ops.push(o);break}if(s[2])n.ops.pop();n.trys.pop();continue}o=t.call(e,n)}catch(e){o=[6,e];i=0}finally{r=s=0}if(o[0]&5)throw o[1];return{value:o[0]?o[1]:void 0,done:true}}};var __spreadArray=this&&this.__spreadArray||function(e,t){for(var n=0,r=t.length,i=e.length;n<r;n++,i++)e[i]=t[n];return e};import{r as registerInstance,h,H as Host}from"./index-55faf181.js";import{i as injectContext}from"./index-8d5c9a8e.js";import"./context-8273b228.js";import"./state-tunnel-04c0b67a.js";function wrapContent(e){return h(Host,{class:"row justify-content-center mt-3"},e)}var DvnAppMembershipConsent=function(){function e(e){var t=this;registerInstance(this,e);this.agreements=[];this.consentedAgreements=[];this.onAgree=function(e){return __awaiter(t,void 0,void 0,(function(){var t;return __generator(this,(function(n){t=this.consentedAgreements.some((function(t){return t._id===e._id}));if(t){this.consentedAgreements=this.consentedAgreements.filter((function(t){return t._id!==e._id}))}else{this.consentedAgreements=__spreadArray(__spreadArray([],this.consentedAgreements),[e])}return[2]}))}))};this.onSubmit=function(){return __awaiter(t,void 0,void 0,(function(){var e,t,n,r,i;var s=this;return __generator(this,(function(o){switch(o.label){case 0:e=this.consentedAgreements;t=[];for(n=0;n<e.length;n++){t=__spreadArray(__spreadArray([],t),[this.apiUye.consentAgreement(e[n]._id)])}return[4,Promise.all(t).catch((function(e){return s.error=e}))];case 1:r=o.sent();if(!r)return[2];return[4,this.apiUye.updateMembership(this.membership.config._id,this.membership._id,{consents:r}).catch((function(e){return s.error=e}))];case 2:i=o.sent();if(!i)return[2];this.appContextInvalidator();return[2]}}))}))}}e.prototype.componentDidLoad=function(){var e=this;var t=this.membership.config.agreements;if(this.agreements.length>=t.length){return}for(var n=0;n<t.length;n++){this.apiUye.getAgreement(t[n]._id).then((function(t){return e.agreements=__spreadArray(__spreadArray([],e.agreements),[t])}),(function(t){return e.error=t}))}};e.prototype.render=function(){var e=this;var t,n;var r=this,i=r.agreements,s=r.consentedAgreements,o=r.membership;var a=o.config;if(i.length!==a.agreements.length){return wrapContent(h("div",{class:"col-4 d-flex flex-column justify-content-center align-items-center mt-3"},h("div",{class:"d-flex justify-content-center"},h("dvn-progress",{indefinite:true}))))}return wrapContent(h("div",{class:"col-sm-12 col-md-8"},h("div",{class:"d-flex flex-column"},h("dvn-app-space-message-card",{space:o.config.space},o.config.space.name," requires you to read and accept these terms and agreements."),i.map((function(t,n){var r=s.some((function(e){return e._id===t._id}));return h("dvn-card",{leaned:n%2===0,leanedSides:true,elevation:0},h("dvn-card-header",{title:t.title,slot:"header"},h("div",{slot:"action"},h("dvn-button",{onClick:function(){return e.selectedAgreement=t},scale:"small",view:"outline"},"Read Agreement"))),h("dvn-checkbox",{leaned:true,checked:r,label:"I read and accept the terms in the condition",onChange:function(){return e.onAgree(t)}}))})),h("dvn-button",{fill:true,disabled:s.length!==i.length,leaned:true,onClick:function(){return e.onSubmit()},tint:"primary"},"Give Consent"),h("dvn-dialog",{title:(t=this.selectedAgreement)===null||t===void 0?void 0:t.title,shown:!!this.selectedAgreement,onDismiss:function(){return e.selectedAgreement=undefined}},h("dvn-markdown",{content:(n=this.selectedAgreement)===null||n===void 0?void 0:n.content})))))};return e}();injectContext(DvnAppMembershipConsent);export{DvnAppMembershipConsent as dvn_app_membership_consent};