(()=>{"use strict";const e=window.wc.blocksCheckout,t=window.React,n=window.wp.i18n,o=window.wp.element,c=window.lodash,{CheckboxControl:a}=window.wc.blocksCheckout,s=JSON.parse('{"apiVersion":2,"name":"cleverreach-wc/checkout","version":"1.0.0","title":"Alternative Shipping Options Block","category":"woocommerce","description":"Adds a select field to let the shopper choose alternative shipping instructions.","supports":{"html":false,"align":false,"multiple":false,"reusable":false},"parent":["woocommerce/checkout-contact-information-block"],"attributes":{"lock":{"type":"object","default":{"remove":true,"move":true}},"text":{"type":"string","default":""}},"textdomain":"cleverreach-wc"}');(0,e.registerCheckoutBlock)({metadata:s,component:({checkoutExtensionData:e,extensions:s})=>{const{setExtensionData:l}=e;var i=wc.wcSettings.getSetting("cleverreach-wc_data");const[r,d]=(0,o.useState)(i.checked),[u,p]=(0,o.useState)({display:"none"}),[h,m]=(0,o.useState)({display:"none"}),w=(0,o.useRef)(null);return(0,o.useCallback)((0,c.debounce)(((e,t,n)=>{l(e,t,n)}),1e3),[l]),(0,o.useEffect)((()=>{l("cleverreach-wc","is_subscribed",i.checked),document.getElementById("email").addEventListener("focusout",(async function(e){await fetch(i.listener_url,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({billing_email:e.target.value})})}))}),[l]),i.is_checkbox_disabled?(0,t.createElement)(t.Fragment,null):(0,t.createElement)(t.Fragment,null,(0,t.createElement)(a,{id:i.newsletter_status_field,name:i.newsletter_status_field,label:i.newsletter_caption,checked:r,onChange:async e=>{if(d(e),e&&i.is_abandoned_cart_enabled)try{const t=await fetch(i.subscribe_url,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({billing_email:email.value,cr_status:e})}),n=await t.json();console.log("Response:",n),p({display:"block"}),m({display:"block"}),w.current=setTimeout((function(){p({display:"none"}),m({display:"none"})}),1e3*i.ac_time)}catch(e){console.error("Error:",e)}l("cleverreach-wc","is_subscribed",e)}}),(0,t.createElement)("label",{style:u},i.subscription_success_message),(0,t.createElement)("a",{style:h,onClick:async e=>{e.preventDefault();try{const e=await fetch(i.undo_url,{method:"POST",headers:{"Content-Type":"application/json"}});console.log("Response:",await e.json()),d(!1),p({display:"none"}),m({display:"none"}),clearTimeout(w.current)}catch(e){console.error("Error:",e)}}},(0,n.__)("Undo","cleverreach-wc")))}})})();