(()=>{"use strict";const e=window.wp.element,t=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":2,"name":"pplcz/whisperer-shop-block","version":"1.0.0","title":"Selection block","category":"Whisperer","parent":["woocommerce/checkout-contact-information-block"],"attributes":{"lock":{"type":"object","default":{"remove":true,"move":false}}},"textdomain":"checkout-block-example","editorScript":"file:./build/index.js"}'),n=window.wc.blocksCheckout,a=window.wp.data,i=window.React,{registerPlugin:r}=window.wp.plugins,l={metadata:t,component:t=>{var r,l,o;const{checkoutExtensionData:c}=t,{cart:s,payment:p}=(0,a.useSelect)((e=>({cart:e("wc/store/cart").getCartData(),payment:e("wc/store/payment").getActivePaymentMethod()}))),[u,m]=(0,i.useState)(""),[d,h]=(0,i.useState)(!1),[k,w]=(0,i.useState)(!1),[y,v]=(0,i.useState)(!1),[g,f]=(0,i.useState)([]);return(0,i.useEffect)((()=>{y&&v(!1)}),[null!==(r=s?.shippingAddress?.address_1)&&void 0!==r?r:"",null!==(l=s?.shippingAddress?.city)&&void 0!==l?l:"",null!==(o=s?.shippingAddress?.postcode)&&void 0!==o?o:""]),(0,i.useEffect)((()=>{const e=setTimeout((()=>{if(u){w(!0);const e=u.split(",").map(((e,t)=>{switch(t){case 0:return`street=${encodeURIComponent(e)}`;case 1:return`city=${encodeURIComponent(e)}`;case 2:return`zipCode=${encodeURIComponent(e)}`}return null})).filter((e=>!!e)).join("&");fetch(s.extensions.pplcz_whisperer.url+"?"+e).then((e=>e.json())).then((e=>{f(e)})).finally((()=>w(!1)))}}),700);return()=>clearTimeout(e)}),[u]),s?.extensions.pplcz_whisperer?.active?(0,e.createElement)(i.Fragment,null,(0,e.createElement)("div",{className:"wc-block-components-text-input "+(d||u?"is-active":"")},(0,e.createElement)("input",{value:u,onChange:e=>{m(e.target.value),f((e=>e.length>0?[]:e))},onFocus:e=>{h(!0)},onBlur:e=>{h(!1)},type:"text",id:"whisperer","aria-label":"Vyhledání ulice"}),(0,e.createElement)("svg",{style:{position:"relative"},xmlns:"http://www.w3.org/2000/svg",width:"2em",height:"2em",viewBox:"0 0 200 200"},(0,e.createElement)("circle",{fill:"none",strokeOpacity:"1",stroke:"#FF156D",strokeWidth:".5",cx:"100",cy:"100",r:"0"},(0,e.createElement)("animate",{attributeName:"r",calcMode:"spline",dur:"2",values:"1;80",keyTimes:"0;1",keySplines:"0 .2 .5 1",repeatCount:"indefinite"}),(0,e.createElement)("animate",{attributeName:"stroke-width",calcMode:"spline",dur:"2",values:"0;25",keyTimes:"0;1",keySplines:"0 .2 .5 1",repeatCount:"indefinite"}),(0,e.createElement)("animate",{attributeName:"stroke-opacity",calcMode:"spline",dur:"2",values:"1;0",keyTimes:"0;1",keySplines:"0 .2 .5 1",repeatCount:"indefinite"}))),(0,e.createElement)("label",{for:"whisperer"},"Vyhledání ulice")),g.length?(0,e.createElement)(i.Fragment,null,"Kliknutím na konkretní ulici se zapíše do odesílací adresy, kterou pak zkontrolujte a doplňte, nebo výběr ",(0,e.createElement)("a",{href:"#",onClick:e=>{e.preventDefault(),f([])}},"zavřete."),(0,e.createElement)("ul",null,g.map(((t,a)=>(0,e.createElement)("li",{key:a},(0,e.createElement)("a",{href:"#",onClick:e=>{f([]),(0,n.extensionCartUpdate)({namespace:"pplcz_whisperer",data:{address:t}}),v(!0)}},t.street,", ",t.zipCode,", ",t.city)))))):null):null}};(0,n.registerCheckoutBlock)(l)})();