1import{r as i,R as r}from"./vendor-58675f0b.js";import{a as T}from"./js.cookie-edb2da2a.js";const D="compliance-modal-step-title-",F="compliance-modal:open",$="AcceptedComplianceRootModals",W=7,B=(d,s,c)=>{const n=(T.get(s)||"").split("|").filter(Boolean);n.includes(d)||(n.push(d),T.set(s,n.join("|"),{expires:c,path:"/"}))},H=(d,s)=>{if(d.childModals.length===0||s.length===0)return null;const c=d.childModals.filter(n=>n.showWhenUserSelected&&s.includes(n.showWhenUserSelected.id));return c.length===0?null:c.length===1?c[0]:s.every(n=>n===s[0])&&c.find(n=>{var u;return((u=n.showWhenUserSelected)==null?void 0:u.id)===s[0]})||c[c.length-1]},K=d=>d.questions.some(s=>s.actions.length>1),R=d=>d.questions.some(s=>s.actions.length>0),V=(d,s)=>d.questions.filter(f=>f.actions.length>0).every(f=>s.has(f.question.id)),G=({closeLabel:d="Close modal",cookieName:s=$,cookieMaxAgeDays:c})=>{const f=(()=>{const e=c!==void 0?parseFloat(c):NaN;return Number.isFinite(e)&&e>0?e:W})(),n=i.useRef(null),[u,C]=i.useState(!1),[y,O]=i.useState(null),[S,P]=i.useState(),[_,b]=i.useState([]),[g,A]=i.useState([]),w=i.useRef(null),t=_[_.length-1]??null,L=i.useMemo(()=>t?g.filter(e=>e.stepId===t.modal.id):[],[g,t]),h=i.useCallback((e,o)=>{const a=w.current;w.current=null;const l=y==null?void 0:y.modal.id;e==="approved"&&l&&B(l,s,f),C(!1);
1const m={outcome:e,productId:S,rootModalId:l,finalStepId:o.modal.id,answers:g};a==null||a(m),document.dispatchEvent(new CustomEvent("compliance-modal:complete",{detail:m}))},[g,s,y,f,S]);i.useEffect(()=>{const e=o=>{const a=o,{data:l,productId:m,onComplete:E}=a.detail;w.current=E??null,O(l),P(m),b([l]),A([]),C(!0)};return document.addEventListener(F,e),()=>document.removeEventListener(F,e)},[]),i.useEffect(()=>{const e=n.current;if(e)if(u&&!e.open)if(e.isConnected)try{e.showModal(),document.body.style.overflow="hidden"}catch{requestAnimationFrame(()=>{var a;(a=n.current)!=null&&a.isConnected&&u&&!n.current.open&&(n.current.showModal(),document.body.style.overflow="hidden")})}else requestAnimationFrame(()=>{var o;(o=n.current)!=null&&o.isConnected&&u&&!n.current.open&&(n.current.showModal(),document.body.style.overflow="hidden")});else!u&&e.open&&(e.close(),document.body.style.removeProperty("overflow"))},[u]);const I=i.useCallback(()=>{t&&w.current?h("dismissed",t):(C(!1),document.body.style.removeProperty("overflow"))},[t,h]),N=i.useCallback((e,o)=>{const a=o.map(v=>v.actionId),l=H(e,a);if(l){b(v=>[...v,l]);return}const m=!R(e)&&e.childModals.length===0,E=e.childModals.length===0&&e.questions.some(v=>v.actions.length>0);if(m)h("denied",e);else if(E){const v=_.length>1&&_[_.length-2].childModals.some(p=>{var q,k;return p.modal.id===e.modal.id&&((k=(q=p.showWhenUserSelected)==null?void 0:q.value)==null?void 0:k.toLowerCase())==="no"});h(v?"denied":"approved",e)}else h("denied",e)},[h,_]),U=i.useCallback((e,o)=>{if(!t)return;const a=[...g.filter(p=>!(p.stepId===t.modal.id&&p.questionId===e)),{stepId:t.modal.id,questionId:e,actionId:o.id,actionValue:o.value}];A(a);const l=a.filter(p=>p.stepId===t.modal.id),m=K(t),E=new Set(l.map(p=>p.questionId));(m?V(t,E):!0)&&N(t,l)},[N,g,t]);if(i.useEffect(()=>{if(!u||!t||R(t)||t.childModals.length>0||t.modal.title)return;const e=setTimeout(()=>h("denied",t),0);return()=>clearTimeout(e)},[t,h,u]),!y||!t)return null;const M=`${D}${t.modal.id}`,x=t.questions.filter(e=>e.question.text||e.actions.length>0);return r.createElement("dialog",{ref:n,className:"compliance-modal","aria-labelledby":t.modal.title?M:void 0,onClick:e=>{var o;e.target===e.currentTarget&&((o=n.current)!=null&&o.open)&&I()}},r.createElement("div",{className:"compliance-modal__container"},r.createElement("div",{className:"compliance-modal__header"},r.createElement("button",{type:"button",className:"compliance-modal__close","aria-label":d,onClick:I},r.createElement("svg",{className:"compliance-modal__close-icon","aria-hidden":"true"},r.createElement("use",{xlinkHref:"#close"})))),r.createElement("div",{className:"compliance-modal__content"},r.createElement("div",{className:"compliance-modal__step is-active"},t.modal.title&&r.createElement("h2",{className:"compliance-modal__title",id:M},t.modal.title),x.length>0&&r.createElement("div",{className:"compliance-modal__questions"},x.map(({question:e,actions:o})=>{const a=o.length>1;return r.createElement("div",{key:e.id,className:"compliance-modal__question","data-question-id":e.id},e.text&&r.createElement("p",{className:"compliance-modal__question-text"},e.text),o.length>0&&r.createElement("div",{className:`compliance-modal__actions${a?" compliance-modal__actions--inline":""}`,role:"group","aria-label":e.text||void 0},o.map(l=>{const m=L.some(E=>E.questionId===e.id&&E.actionId===l.id);return r.createElement("button",{key:l.id,type:"button",className:`btn compliance-modal__action${a?" btn--outline":""}${m?" is-selected":""}`,"data-action-id":l.id,"data-action-value":l.value,"aria-pressed":a?m:void 0,onClick:()=>U(e.id,l)},l.text)})))}))))))};export{G as default}; 2//# sourceMappingURL=index-65c6dfb4.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.