(()=>{"use strict";const e=window.wc.blocksCheckout,t=window.React,n=window.wp.element,o=window.wp.i18n,i=window.wp.data,{ExperimentalOrderMeta:s}=wc.blocksCheckout;function l({handleDeliveryPointChange:e,inpostDeliveryPoint:n}){return(0,t.createElement)("div",{className:"inpost-parcel-locker-wrap",style:{display:"none"}},(0,t.createElement)("input",{value:n,type:"text",id:"inpost-parcel-locker-id",onChange:e}))}const c=JSON.parse('{"apiVersion":2,"name":"inpost-pl/block","version":"2.0.0","title":"Inpost PL Shipping Options Block","category":"woocommerce","description":"Adds map button and add input to save delivery point data.","supports":{"html":false,"align":false,"multiple":false,"reusable":false},"parent":["woocommerce/checkout-shipping-methods-block"],"attributes":{"lock":{"type":"object","default":{"remove":true,"move":true}},"text":{"type":"string","source":"html","selector":".wp-block-inpost-pl","default":""}},"textdomain":"inpost-for-woocommerce","editorStyle":""}');(0,e.registerCheckoutBlock)({metadata:c,component:({checkoutExtensionData:e,extensions:c})=>{let a=!1,r=null,p="Wybierz punkt odbioru";"undefined"!=typeof wcSettings&&null!==wcSettings&&"inpost_pl_block_data"in wcSettings&&"map_btn_text"in wcSettings.inpost_pl_block_data&&(p=wcSettings.inpost_pl_block_data.map_btn_text);const[d,u]=(0,n.useState)(""),{setExtensionData:_}=e,m="inpost-pl-delivery-point-error",{setValidationErrors:h,clearValidationError:f}=(0,i.useDispatch)("wc/store/validation");let g=(0,i.useSelect)((e=>e("wc/store/cart").getShippingRates()));const[k,w]=(0,n.useState)(!1),b=(0,i.useSelect)((e=>e("wc/store/checkout").prefersCollection()),[]);(0,n.useEffect)((()=>{w(b)}),[b]),(0,n.useEffect)((()=>{const e=()=>{const e=document.getElementById("shipping-method");if(!e)return;const t=e.querySelectorAll(".wc-block-checkout__shipping-method-option"),n=e.querySelector(".wc-block-checkout__shipping-method-option--selected");if(n&&t.length>0){const e=Array.from(t).indexOf(n),o=1===e;console.log("Selected shipping method index:",e),console.log("isPickup shipping method:",o),o&&f(m),w(o)}};e();const t=document.getElementById("shipping-method");if(t){t.addEventListener("click",(t=>{setTimeout(e,100)}));const n=new MutationObserver((()=>{e()}));return n.observe(t,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["class"]}),()=>{n.disconnect()}}}),[]);const y=wcSettings.inpost_pl_block_data&&wcSettings.inpost_pl_block_data.configured_methods?wcSettings.inpost_pl_block_data.configured_methods:[];if(null!=g){let e=g[Object.keys(g)[0]];if(null!=e&&e.hasOwnProperty("shipping_rates")){const t=e.shipping_rates,n=[];if(null!=t){for(let e of t)if("pickup_location"!==e.method_id){if(!0===e.selected)if(r=e.instance_id,-1!==e.method_id.indexOf("easypack_parcel_machines"))a=!0;else{let e=y[r];null!=e&&e.hasOwnProperty("need_map")&&(a=!0)}n.push(e)}if(!r&&n.length>0){const e=document.getElementsByClassName("wc-block-components-shipping-rates-control")[0];if(null!=e){const t=e.querySelector('input[name^="radio-control-"]:checked');if(null!=t){let e=t.getAttribute("id");if(null!=e){let t=e.split(":");if(r=t[t.length-1],-1!==t[0].indexOf("easypack_parcel_machines"))a=!0;else{let e=y[r];null!=e&&e.hasOwnProperty("need_map")&&(a=!0)}}}}}}}}const[v,S]=(0,n.useState)([]);return(0,n.useEffect)((function(){const e=function(){S(function(){const e=document.querySelector(".wc-block-components-shipping-rates-control");if(e){const t=e.querySelectorAll('input[name^="radio-control-"]');return Array.from(t).map((function(e){return{id:e.id,value:e.value,checked:e.checked}}))}return[]}())};e();const t=new MutationObserver(e);return t.observe(document.body,{subtree:!0,childList:!0}),()=>t.disconnect()}),[]),(0,n.useEffect)((function(){(()=>{let e=y;v.forEach((function(t){if(t.value&&t.value.indexOf(":")>-1){const[n,o]=t.value.split(":");let i=!1,s=null;if(null!=e&&(s=e[o],null!=s&&"inpost_icon"in s)){let e=s.inpost_icon;e&&null!=e&&(i=e)}const l=document.querySelector(`span[id="${t.id}__label"]`);if(i&&l&&!l.querySelector(".inpost_icon")){let e='","delivery_terms"in s&&s.delivery_terms&&(e+='',e+=s.delivery_terms,e+=""),e+="",l.insertAdjacentHTML("beforeend",e)}}}))})()}),[v]),(0,n.useEffect)((()=>{_("inpost","inpost-parcel-locker-id",d),d||!a||k?f(m):h({[m]:{message:(0,o.__)("Parcel locker must be chosen.","inpost-for-woocommerce"),hidden:!1}})}),[d,k,a,_,f,h]),(0,t.createElement)(t.Fragment,null,a&&!k&&(0,t.createElement)(t.Fragment,null,(0,t.createElement)("button",{className:"button alt easypack_show_geowidget",id:"easypack_block_type_geowidget"},p),(0,t.createElement)("div",{id:"inpost_pl_selected_point_data_wrap",className:"inpost_pl_selected_point_data_wrap",style:{display:"none"}}),(0,t.createElement)(s,null,(0,t.createElement)(l,{inpostDeliveryPoint:d,handleDeliveryPointChange:e=>{const t=e.target.value;u(t)}}))))}})})();