(()=>{"use strict";var e={20:(e,o,i)=>{var t=i(609),c=Symbol.for("react.element"),a=(Symbol.for("react.fragment"),Object.prototype.hasOwnProperty),d=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,r={key:!0,ref:!0,__self:!0,__source:!0};function n(e,o,i){var t,n={},s=null,f=null;for(t in void 0!==i&&(s=""+i),void 0!==o.key&&(s=""+o.key),void 0!==o.ref&&(f=o.ref),o)a.call(o,t)&&!r.hasOwnProperty(t)&&(n[t]=o[t]);if(e&&e.defaultProps)for(t in o=e.defaultProps)void 0===n[t]&&(n[t]=o[t]);return{$$typeof:c,type:e,key:s,ref:f,props:n,_owner:d.current}}o.jsx=n,o.jsxs=n},848:(e,o,i)=>{e.exports=i(20)},609:e=>{e.exports=window.React}},o={};function i(t){var c=o[t];if(void 0!==c)return c.exports;var a=o[t]={exports:{}};return e[t](a,a.exports,i),a.exports}i.n=e=>{var o=e&&e.__esModule?()=>e.default:()=>e;return i.d(o,{a:o}),o},i.d=(e,o)=>{for(var t in o)i.o(o,t)&&!i.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:o[t]})},i.o=(e,o)=>Object.prototype.hasOwnProperty.call(e,o);const t=window.wc.blocksCheckout,c=window.wp.element,a=window.wp.i18n,d=window.lodash,r=window.wc.wcSettings,n=window.CDEKWidget;var s=i.n(n),f=i(848);const l=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":3,"name":"cdek/checkout-map-block","version":"1.0.0","title":"CDEK Delivery Map","category":"widgets","description":"Adds a map on checkout to allow user select office to pickup from.","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","default":""}},"textdomain":"cdekdelivery"}');(0,t.registerCheckoutBlock)({metadata:l,component:({checkoutExtensionData:e,extensions:o,cart:i,validation:t})=>{const{apiKey:n,officeDeliveryModes:l,lang:p}=(0,r.getSetting)("official_cdek_data"),[_,u]=(0,c.useState)(!1),[w,k]=(0,c.useState)(null),{setExtensionData:h}=e,{setValidationErrors:g,clearValidationError:m,getValidationError:v}=t,y=(0,d.debounce)(((e,o,i)=>{h(e,o,i)}),500),b=(0,c.useCallback)((0,d.debounce)(((e,o)=>{if(""===o||!i.cartNeedsShipping)return y("official_cdek","office_code",null),void m("official_cdek_office");const t=e.flatMap((e=>e.shipping_rates)).find((e=>e.selected));return t&&Object.prototype.hasOwnProperty.call(t,"method_id")&&"official_cdek"===t.method_id?-1===l.indexOf(parseInt(t.meta_data.find((e=>"_official_cdek_tariff_mode"===e.key)).value))?(y("official_cdek","office_code",null),void m("official_cdek_office")):(g({official_cdek_office:{message:(0,a.__)("Choose pick-up","cdekdelivery"),hidden:!0}}),void 0===window.widget?window.widget=new(s())({apiKey:n,lang:p,debug:!0,defaultLocation:e[0].destination.city,officesRaw:JSON.parse(o),hideDeliveryOptions:{door:!0},onChoose(e,o,i){y("official_cdek","office_code",i.code),m("official_cdek_office")}}):(window.widget.clearSelection(),window.widget.updateOfficesRaw(JSON.parse(o)),window.widget.updateLocation(e[0].destination.city)),void u(!0)):(y("official_cdek","office_code",null),void m("official_cdek_office"))}),1e3),[]);return(0,c.useEffect)((()=>{u(!1),i.isLoading||i.isLoadingRates||!o.official_cdek?m("official_cdek_office"):b(i.shippingRates,o.official_cdek.points||[])}),[i.isLoading,i.isLoadingRates,i.shippingRates,o.official_cdek]),(0,c.useEffect)((()=>{k(v("official_cdek_office"))})),(0,f.jsxs)("div",{className:"wp-block-shipping-cdek-map",style:{display:_?"block":"none"},children:[(0,f.jsx)("div",{id:"cdek-map",style:{height:"600px",border:!1===w?.hidden?"1px solid #cc1818":""}}),!1===w?.hidden&&(0,f.jsx)("div",{className:"wc-block-components-validation-error",role:"alert",children:(0,f.jsx)("p",{children:w.message})})]})}})})();