Loading
function(l,t,d){d.d(t,{w:()=>o,consentMachine:()=>n});var i=d(209688),c=d(588233),e=d(171251),a=d(64755);async function s(l,t){if(!l)throw Error("Combined consent id is required");let d=await i.t.get(e.t.getCombinedConsent,{signal:t,query:{id:l,language:"en"}});if(!d.ok)throw Error(`GET ${e.t.getCombinedConsent} failed: ${d.status} ${d.statusText}`);return d.data}async function Z(l,t){let d=await i.t.post(e.t.signCombinedConsent,l,{signal:t});if(!d.ok)throw Error(`POST ${e.t.signCombinedConsent} failed: ${d.status} ${d.statusText}`)}let n=(0,a.t)({types:{context:{},events:{},input:{}},actors:{fetchConsent:(0,a.a)(async({input:l,signal:t})=>s(l.consentId,t)),submitConsent:(0,a.a)(async({input:l,signal:t})=>{await Z({languageConsentId:l.languageConsentId,checkboxes:l.checkboxes.reduce((l,t)=>(l[t.id]=t.checked,l),{})},t)})},actions:{setConsentData:(0,a.r)(({event:l})=>{let t=l.output;return{title:t.title,richText:t.terms,languageConsentId:t.languageConsentId,checkboxes:t.consents.map(l=>({id:l.checkboxId,label:l.consentText,required:!l.optional,checked:!1})),error:void 0}}),toggleCheckbox:(0,a.r)(({context:l,event:t})=>{let d=t.checkboxId;return{checkboxes:l.checkboxes.map(l=>l.id===d?{...l,checked:!l.checked}:l)}}),setError:(0,a.r)(({event:l})=>({error:String(l.error)})),clearError:(0,a.r)({error:()=>void 0}),resetContext:(0,a.r)(({context:l})=>({config:l.config,title:"",richText:"",languageConsentId:"",checkboxes:[],error:void 0}))},guards:{canSubmit:({context:l})=>l.checkboxes.filter(l=>l.required).every(l=>l.checked)}}).createMachine({id:"consent",initial:"idle",context:({input:l})=>({config:l.config,title:"",richText:"",languageConsentId:"",checkboxes:[],error:void 0}),states:{idle:{on:{LOAD:{target:"loading",actions:"clearError"}}},loading:{invoke:{id:"fetchConsent",src:"fetchConsent",input:({context:l})=>({consentId:String(l.config.combinedConsents??l.config.consentId??"")}),onDone:{target:"display",actions:"setConsentData"},onError:{target:"error",actions:"setError"}}},display:{on:{TOGGLE_CHECKBOX:{actions:"toggleCheckbox"},SUBMIT:{target:"submitting",guard:"canSubmit"},RETRY:{target:"loading",actions:"clearError"}}},submitting:{invoke:{id:"submitConsent",src:"submitConsent",input:({context:l})=>({languageConsentId:l.languageConsentId,checkboxes:l.checkboxes}),onDone:{target:"finished"},onError:{target:"display",actions:"setError"}}},error:{on:{RETRY:{target:"loading",actions:"clearError"},RESET:{target:"idle",actions:"resetContext"}}},finished:{type:"final"}}});function b(l){let{context:t}=l,d=t.checkboxes.filter(l=>l.required).every(l=>l.checked);return l.matches("idle")?{status:"idle"}:l.matches("loading")?{status:"loading"}:l.matches("display")?{status:"display",title:t.title,richText:t.richText,checkboxes:t.checkboxes,canSubmit:d,error:t.error}:l.matches("submitting")?{status:"submitting",title:t.title,richText:t.richText,checkboxes:t.checkboxes,canSubmit:!1}:l.matches("finished")?{status:"finished"}:l.matches("error")?{status:"error",error:t.error??"Unknown error"}:{status:"idle"}}function m({actor:l,trackElementClicked:t}){return{load(){l.send({type:"LOAD"})},toggleCheckbox(t){l.send({type:"TOGGLE_CHECKBOX",checkboxId:t})},submit(){t?.("submit"),l.send({type:"SUBMIT"})},retry(){t?.("retry"),l.send({type:"RETRY"})},reset(){l.send({type:"RESET"})}}}function o(l){return(0,a.c)({actor:(0,a.s)(n,{input:{config:l.config}}).start(),mapState:b,createApi:m,instrumentation:(0,c.o)(c.n.combinedConsent)})}}