"use strict";(globalThis.webpackWcGzdBlocksJsonp=globalThis.webpackWcGzdBlocksJsonp||[]).push([[685],{5626:(e,c,t)=>{t.r(c),t.d(c,{default:()=>p});var o=t(6087),s=t(1e3),n=t(8468),a=t.n(n),d=t(2485),r=t.n(d),i=t(7677),h=t(8053),l=t(4848);const u=({show:e,url:c,onClose:t,content:s})=>{const[n,a]=(0,o.useState)(!0),[d,r]=(0,o.useState)("");let u="";if(s)r(s),a(!1);else if(c)try{const e=new URL(c);u=c.toString().substring(e.origin.length)}catch{}return(0,o.useEffect)(()=>{e?document.body.classList.add("checkout-modal-open"):document.body.classList.remove("checkout-modal-open"),u&&(a(!0),r(""),fetch(u,{method:"get"}).then(e=>e.text()).then(e=>{r(e),a(!1)}).catch(function(e){a(!1)}))},[u,r,e]),e?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("div",{className:"wc-gzd-checkout-modal-bg"}),(0,l.jsx)("div",{className:"wc-gzd-checkout-modal-wrapper",children:(0,l.jsxs)("div",{className:"wc-gzd-checkout-modal",children:[(0,l.jsx)("div",{className:"actions",children:(0,l.jsx)("a",{className:"wc-gzd-checkout-modal-close",onClick:e=>{document.body.classList.remove("checkout-modal-open"),t(e)},children:(0,l.jsx)(i.A,{className:"wc-gzd-checkout-modal-close-icon",icon:h.A,size:24})})}),n?(0,l.jsx)("div",{className:"content is-loading",children:(0,l.jsx)("span",{className:"wc-block-components-spinner","aria-hidden":"true"})}):(0,l.jsx)(l.Fragment,{children:(0,l.jsx)("div",{className:"content",dangerouslySetInnerHTML:{__html:d}})})]})})]}):null};var m=t(9761),b=t(7143),k=t(7594),x=t(5703);const g=e=>{const{onChangeCheckbox:c,checkbox:t}=e,{shouldCreateAccount:s,customerId:n}=(0,b.useSelect)(e=>{const c=e(k.CHECKOUT_STORE_KEY);return{customerId:c.getCustomerId(),shouldCreateAccount:c.getShouldCreateAccount()}}),a=!1===(0,x.getSetting)("checkoutAllowsGuest",!1)&&!n;return(0,o.useEffect)(()=>{c(s||a?{...t,hidden:!1}:{...t,hidden:!0})},[s]),(0,l.jsx)(m.A,{...e})},_=e=>{const[c,t]=(0,o.useState)({}),{onChangeCheckbox:s,checkbox:n}=e,{billingAddress:a,paymentData:d,currentPaymentMethod:r}=(0,b.useSelect)(e=>{const c=e(k.CART_STORE_KEY),t=e(k.PAYMENT_STORE_KEY);return{billingAddress:c.getCartData().billingAddress,paymentData:t.getPaymentMethodData(),currentPaymentMethod:t.getActivePaymentMethod()}});return(0,o.useEffect)(()=>{const e={country:a.country,postcode:a.postcode,city:a.city,street:a.address_1,address_2:a.address_2,account_holder:d.hasOwnProperty("direct_debit_account_holder")?d.direct_debit_account_holder:"",account_iban:d.hasOwnProperty("direct_debit_account_iban")?d.direct_debit_account_iban:"",account_swift:d.hasOwnProperty("direct_debit_account_bic")?d.direct_debit_account_bic:""};t(e),s("direct-debit"===r&&e.account_holder&&e.account_iban&&e.account_swift?{...n,hidden:!1}:{...n,hidden:!0})},[a,d,r]),(0,l.jsx)(m.A,{...e,setModalUrl:t=>{t+="&"+new URLSearchParams(c).toString(),e.setModalUrl(t)}})},p=({children:e,checkoutExtensionData:c,extensions:t,cart:n,className:d})=>{const[i,h]=(0,o.useState)(!1),{setExtensionData:b}=c,k=t.hasOwnProperty("woocommerce-germanized")?t["woocommerce-germanized"]:{},x=k.hasOwnProperty("checkboxes")?k.checkboxes:[],p=x.reduce((e,c)=>({...e,[c.id]:{...c,hidden:c.default_hidden,checked:c.default_checked}}),{}),[w,y]=(0,o.useState)(p),[C,f]=(0,o.useState)(""),j=(0,o.useRef)(!1),S=e=>Object.values(e).filter(e=>e.checked||!e.has_checkbox&&!e.hidden?e:null);(0,o.useEffect)(()=>{b("woocommerce-germanized","checkboxes",S(w))},[w]);const E=(0,o.useCallback)(e=>{y(c=>{const t=c&&c.hasOwnProperty(e.id)&&c[e.id].checked!==e.checked,o={...c,[e.id]:{...e}};return t&&(0,s.extensionCartUpdate)({namespace:"woocommerce-germanized-checkboxes",data:{checkboxes:S(o)}}),o})},[b,w,y,s.extensionCartUpdate]);return(0,o.useEffect)(()=>{if(j.current){let e={};Object.keys(p).map(c=>{const t=w.hasOwnProperty(c)?{checked:w[c].checked,hidden:w[c].hidden}:{};e[c]={...p[c],...t}}),a().isEqual(e,w)||y(e)}j.current=!0},[x]),(0,l.jsxs)("div",{className:r()("wc-gzd-checkboxes",d),children:[(0,l.jsx)(u,{show:i,url:C,onClose:()=>{h(!1)}}),Object.keys(w).map(e=>{const c={...w[e]};return"sepa"===c.id?(0,l.jsx)(_,{checkbox:c,setShowModal:h,setModalUrl:f,onChangeCheckbox:E},c.id):"privacy"===c.id?(0,l.jsx)(g,{checkbox:c,setShowModal:h,setModalUrl:f,onChangeCheckbox:E},c.id):(0,l.jsx)(m.A,{checkbox:c,setShowModal:h,setModalUrl:f,onChangeCheckbox:E},c.id)})]})}}}]);