"use strict";(self.webpackWcGzdBlocksJsonp=self.webpackWcGzdBlocksJsonp||[]).push([[131],{953:function(e,t,c){c.r(t),c.d(t,{default:function(){return p}});var n=c(9196),o=c(9307),a=c(3554),s=c(2819),d=c.n(s),r=c(4184),l=c.n(r),i=c(1984),u=c(7231),h=({show:e,url:t,onClose:c,content:a})=>{const[s,d]=(0,o.useState)(!0),[r,l]=(0,o.useState)("");let h="";if(a)l(a),d(!1);else if(t)try{const e=new URL(t);h=t.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"),h&&(d(!0),l(""),fetch(h,{method:"get"}).then((e=>e.text())).then((e=>{l(e),d(!1)})).catch((function(e){d(!1)})))}),[h,l,e]),e?(0,n.createElement)(n.Fragment,null,(0,n.createElement)("div",{className:"wc-gzd-checkout-modal-bg"}),(0,n.createElement)("div",{className:"wc-gzd-checkout-modal-wrapper"},(0,n.createElement)("div",{className:"wc-gzd-checkout-modal"},(0,n.createElement)("div",{className:"actions"},(0,n.createElement)("a",{className:"wc-gzd-checkout-modal-close",onClick:e=>{document.body.classList.remove("checkout-modal-open"),c(e)}},(0,n.createElement)(i.Z,{className:"wc-gzd-checkout-modal-close-icon",icon:u.Z,size:24}))),s?(0,n.createElement)("div",{className:"content is-loading"},(0,n.createElement)("span",{className:"wc-block-components-spinner","aria-hidden":"true"})):(0,n.createElement)(n.Fragment,null,(0,n.createElement)("div",{className:"content",dangerouslySetInnerHTML:{__html:r}}))))):null},m=c(2260),k=c(9818),b=c(4801),_=c(4617),g=e=>{const{onChangeCheckbox:t,checkbox:c}=e,{shouldCreateAccount:a,customerId:s}=(0,k.useSelect)((e=>{const t=e(b.CHECKOUT_STORE_KEY);return{customerId:t.getCustomerId(),shouldCreateAccount:t.getShouldCreateAccount()}})),d=!1===(0,_.getSetting)("checkoutAllowsGuest",!1)&&!s;return(0,o.useEffect)((()=>{t(a||d?{...c,hidden:!1}:{...c,hidden:!0})}),[a]),(0,n.createElement)(m.Z,{...e})},E=e=>{const[t,c]=(0,o.useState)({}),{onChangeCheckbox:a,checkbox:s}=e,{billingAddress:d,paymentData:r,currentPaymentMethod:l}=(0,k.useSelect)((e=>{const t=e(b.CART_STORE_KEY),c=e(b.PAYMENT_STORE_KEY);return{billingAddress:t.getCartData().billingAddress,paymentData:c.getPaymentMethodData(),currentPaymentMethod:c.getActivePaymentMethod()}}));return(0,o.useEffect)((()=>{const e={country:d.country,postcode:d.postcode,city:d.city,street:d.address_1,address_2:d.address_2,account_holder:r.hasOwnProperty("direct_debit_account_holder")?r.direct_debit_account_holder:"",account_iban:r.hasOwnProperty("direct_debit_account_iban")?r.direct_debit_account_iban:"",account_swift:r.hasOwnProperty("direct_debit_account_bic")?r.direct_debit_account_bic:""};c(e),a("direct-debit"===l&&e.account_holder&&e.account_iban&&e.account_swift?{...s,hidden:!1}:{...s,hidden:!0})}),[d,r,l]),(0,n.createElement)(m.Z,{...e,setModalUrl:c=>{c+="&"+new URLSearchParams(t).toString(),e.setModalUrl(c)}})},p=({children:e,checkoutExtensionData:t,extensions:c,cart:s,className:r})=>{const[i,u]=(0,o.useState)(!1),{setExtensionData:k}=t,b=c.hasOwnProperty("woocommerce-germanized")?c["woocommerce-germanized"]:{},_=b.hasOwnProperty("checkboxes")?b.checkboxes:[],p=_.reduce(((e,t)=>({...e,[t.id]:{...t,hidden:t.default_hidden,checked:t.default_checked}})),{}),[w,y]=(0,o.useState)(p),[f,C]=(0,o.useState)(""),x=(0,o.useRef)(!1),S=e=>Object.values(e).filter((e=>e.checked||!e.has_checkbox&&!e.hidden?e:null));(0,o.useEffect)((()=>{k("woocommerce-germanized","checkboxes",S(w))}),[w]);const M=(0,o.useCallback)((e=>{y((t=>{const c=t&&t.hasOwnProperty(e.id)&&t[e.id].checked!==e.checked,n={...t,[e.id]:{...e}};return c&&(0,a.extensionCartUpdate)({namespace:"woocommerce-germanized-checkboxes",data:{checkboxes:S(n)}}),n}))}),[k,w,y,a.extensionCartUpdate]);return(0,o.useEffect)((()=>{if(x.current){let e={};Object.keys(p).map((t=>{const c=w.hasOwnProperty(t)?{checked:w[t].checked,hidden:w[t].hidden}:{};e[t]={...p[t],...c}})),d().isEqual(e,w)||y(e)}x.current=!0}),[_]),(0,n.createElement)("div",{className:l()("wc-gzd-checkboxes",r)},(0,n.createElement)(h,{show:i,url:f,onClose:()=>{u(!1)}}),Object.keys(w).map((e=>{const t={...w[e]};return"sepa"===t.id?(0,n.createElement)(E,{checkbox:t,setShowModal:u,setModalUrl:C,key:t.id,onChangeCheckbox:M}):"privacy"===t.id?(0,n.createElement)(g,{checkbox:t,setShowModal:u,setModalUrl:C,key:t.id,onChangeCheckbox:M}):(0,n.createElement)(m.Z,{checkbox:t,setShowModal:u,setModalUrl:C,key:t.id,onChangeCheckbox:M})})))}}}]);