1(()=>{"use strict";const e=window.wc.blocksCheckout,t=window.React,s=window.wp.element,i=window.wp.components,n=window.wp.data,a=window.lodash,l=()=>wcSettings&&wcSettings["omnivalt-blocks_data"]?wcSettings["omnivalt-blocks_data"]:[],o=e=>{for(let[t,s]of Object.entries(l().methods))if(e==s)return m("Detected Omniva method",s),!0;return!1},r=l().debug,c="OMNIVA BLOCKS DEBUG:",m=(...e)=>{r&&console.log(c,...e)},h=(e,t)=>{r&&(0,s.useEffect)((()=>{console.log(c,'Changed state "'+e+'" value to:',t)}),[t])},_=window.wp.i18n,d=wcSettings["omnivalt-blocks_data"].txt,p=((0,_.__)("Block options","omnivalt"),(0,_.__)("Parcel terminal","omnivalt"),(0,_.__)("Select parcel terminal","omnivalt"),(0,_.__)("Please select parcel terminal","omnivalt"),(0,_.__)("You can choose the parcel terminal on the Checkout page","omnivalt"),(0,_.__)("Loading select field...","omnivalt"),(0,_.__)("Post office","omnivalt"),(0,_.__)("Select post office","omnivalt"),(0,_.__)("Please select post office","omnivalt"),(0,_.__)("You can choose the post office on the Checkout page","omnivalt"),(0,_.__)("Omniva","omnivalt"),(0,_.__)("Matkahuolto","omnivalt"),(0,_.__)("post offices","omnivalt"),(0,_.__)("parcel terminals","omnivalt"),(0,_.__)("Post offices list","omnivalt"),(0,_.__)("Parcel terminals list","omnivalt"),(0,_.__)("Select post office","omnivalt"),(0,_.__)("Select terminal","omnivalt"),(0,_.__)("Enter postcode","omnivalt"),(0,_.__)("Search","omnivalt"),(0,_.__)("Select","omnivalt"),(0,_.__)("Select in map","omnivalt"),(0,_.__)("Use my location","omnivalt"),(0,_.__)("Distance calculated from this point","omnivalt"),(0,_.__)("Place not found","omnivalt"),(0,_.__)("There were no cities found for your search term","omnivalt"),(0,_.__)("Geolocation is not supported","omnivalt"),(0,_.__)("Place not found","omnivalt"),(0,_.__)("Value is too short","omnivalt"),(0,_.__)("Select terminal","omnivalt"),(0,_.__)("parcel terminals","omnivalt"),(0,_.__)("Parcel terminals addresses","omnivalt"),(0,_.__)("Select post office","omnivalt"),(0,_.__)("post offices","omnivalt"),(0,_.__)("Post offices addresses","omnivalt"),(0,_.__)("Enter postcode/address","omnivalt"),(0,_.__)("Show in map","omnivalt"),(0,_.__)("Show more","omnivalt"),e=>{let t="";let s=0;for(;s<e;)t+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".charAt(Math.floor(62*Math.random())),s+=1;return t}),u=(e,t=0)=>(t||(t=5),{value:e,token:p(t)}),f=e=>{for(const t in e)if(Object.hasOwn(e,t))return!1;return!0},v=async e=>{let t=null;try{let s=await fetch(e);t=await s.json()}catch(e){console.error("OMNIVA UTILS:",e)}return t},g=(e,t)=>{e.value=t;const s=new Event("change",{bubbles:!0});e.dispatchEvent(s)},y=()=>({lib:null,elements:{},translations:{},params:{},load_data:function(e){this.elements={org_field:this.set_param(e,"org_field",null),map_container:this.set_param(e,"map_container",null)},this.params={provider:this.set_param(e,"provider","omniva"),terminals_type:this.set_param(e,"terminals_type","terminal"),selected_terminal:this.set_param(e,"selected_terminal",""),icons_url:this.set_param(e,"icons_url",`${l().plugin_url}assets/img/terminal-mapping/`),country:this.set_param(e,"country","LT"),map_icon:this.set_param(e,"map_icon","omnivalt_icon.png")};const t="post"==this.params.terminals_type?d.map.modal_title_post:d.map.modal_title_terminal,s=this.params.provider in d.providers?d.providers[this.params.provider]:d.providers.omniva;this.translations={modal_header:s+" "+t,terminal_list_header:"post"==this.params.terminals_type?d.map.modal_search_title_post:d.map.modal_search_title_terminal,select_pickup_point:"post"==this.params.terminals_type?d.map.select_post:d.map.select_terminal,seach_header:d.map.search_placeholder,search_btn:d.map.search_button,select_btn:d.map.select_button,modal_open_btn:d.map.modal_open_button,geolocation_btn:d.map.use_my_location,your_position:d.map.my_position,nothing_found:d.map.not_found,no_cities_found:d.map.no_cities_found,geolocation_not_supported:d.map.geo_not_supported}},set_param:function(e,t,s=null){return t in e?e[t]:s},init:function(e){this.elements.map_container?(this.lib=new TerminalMappingOmnivalt,this.lib.setImagesPath(this.params.icons_url),this.lib.setTranslation(this.translations),this.lib.dom.setContainerParent(this.elements.map_container),this.lib.setParseMapTooltip(((e,t)=>{let s=e.address+" ["+e.id+"]";return e.comment&&(s+="<br/><i>"+e.comment+"</i>"),s})),this.build_actions(this),this.lib.init({country_code:this.params.country,identifier:"omnivalt",isModal:!0,modalParent:this.elements.map_container,hideContainer:!0,hideSelectBtn:!0,cssThemeRule:"tmjs-default-theme",customTileServerUrl:"https://maps.omnivasiunta.lt/tile/{z}/{x}/{y}.png",customTileAttribution:'© <a href="https://www.omniva.lt">Omniva</a> | Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>',terminalList:e})):this.error("Failed to get a container for the map")},build_actions:function(e){this.lib.sub("tmjs-ready",(function(t){e.lib.map.createIcon("omnivalt_icon",e.params.icons_url+e.params.map_icon),e.lib.map.refreshMarkerIcons();let s=t.map.getLocationById(e.params.selected_terminal);void 0!==s&&null!=s&&(e.lib.dom.setActiveTerminal(s),e.lib.publish("terminal-selected",s))}
1)),this.lib.sub("terminal-selected",(function(t){g(e.elements.org_field,t.id),e.lib.dom.setActiveTerminal(t.id),e.lib.publish("close-map-modal")}))},set_search_value:function(e){""!=(e=e.trim())&&(this.lib.dom.searchNearest(e),this.lib.dom.UI.modal.querySelector(".tmjs-search-input").value=e)},error:function(e){console.error("OMNIVA MAP:",e)}}),w=()=>({map:null,selected:{},terminals:[],elements:{},params:{},translations:{},loaded:!1,load_data:function(e){this.elements={org_field:this.set_param(e,"org_field",null),custom_container:this.set_param(e,"custom_container",null),this_dropdown:null,this_list:null,this_container:null,this_inner_container:null,this_loader:null,this_search:null,this_search_msg:null,this_show_more:null},this.params={provider:this.set_param(e,"provider","omniva"),terminals_type:this.set_param(e,"terminals_type","terminal"),country:this.set_param(e,"country","LT"),max_show:this.set_param(e,"max_show",8),active_timeout:null,autoselect:this.set_param(e,"autoselect",!0),selected_terminal:this.set_param(e,"selected_terminal","")},this.params.provider in d.providers?d.providers[this.params.provider]:d.providers.omniva,this.translations={not_found:d.select.not_found,too_short:d.select.search_too_short,select_terminal:"post"==this.params.terminals_type?d.select.post_select:d.select.terminal_select,enter_address:d.select.enter_address,show_more:d.select.show_more}},set_param:function(e,t,s=null){return t in e?e[t]:s},init:function(){if(f(this.elements))return void this.error("Load data is required before initialization");if(!this.elements.custom_container)return void this.error("Failed to get a container for the custom field");this.elements.org_field.value&&this.set_selected();let e,t=null;this.elements.this_container=document.createElement("div"),this.elements.this_container.classList.add("omnivalt-terminals-list"),this.elements.this_dropdown=document.createElement("div"),this.elements.this_dropdown.classList.add("dropdown"),this.elements.this_dropdown.innerHTML=this.translations.select_terminal,this.update_element_dropdown(),this.elements.this_search=document.createElement("input"),this.elements.this_search.type="text",this.elements.this_search.classList.add("search-input"),this.elements.this_search.placeholder=this.translations.enter_address,this.elements.this_search_msg=document.createElement("span"),this.elements.this_search_msg.classList.add("search-msg"),this.show_element_search_msg(!1),this.elements.this_loader=document.createElement("div"),this.elements.this_loader.classList.add("omnivalt-loader"),this.show_element_loader(!1),this.elements.this_list=document.createElement("ul"),this.elements.this_show_more=document.createElement("div"),this.elements.this_show_more.classList.add("show-more"),e=document.createElement("a"),t=document.createTextNode(this.translations.show_more),e.appendChild(t),e.href="#",this.elements.this_show_more.appendChild(e),this.elements.this_inner_container=document.createElement("div"),this.elements.this_inner_container.classList.add("inner-container"),this.show_element_inner_container(!1),this.elements.this_inner_container.append(this.elements.this_search,this.elements.this_search_msg,this.elements.this_loader,this.elements.this_list,this.elements.this_show_more),this.elements.this_container.append(this.elements.this_dropdown,this.elements.this_inner_container),this.elements.custom_container.append(this.elements.this_container),this.reset_terminals(),this.refresh_element_list(),this.elements.this_show_more.addEventListener("click",(e=>{e.preventDefault(),this.show_element_all_options()})),this.elements.this_dropdown.addEventListener("click",(e=>{this.toggle_dropdown()})),this.elements.org_field.addEventListener("click",(e=>{this.set_selected(),this.update_element_dropdown(),this.elements.this_list.querySelector('li[data-id="'+this.elements.org_field.value+'"').classList.add("selected")})),this.elements.this_search.addEventListener("keyup",(()=>{this.show_element_search_msg(!1),this.show_element_loader(!0),clearTimeout(this.params.active_timeout),this.params.active_timeout=setTimeout((()=>{this.params.autoselect=!1,this.geo_suggest(this.elements.this_search.value)}),400)})),this.elements.this_search.addEventListener("keyup",(e=>{"13"==e.which&&e.preventDefault()})),document.addEventListener("mousedown",(e=>{this.elements.this_container!=e.target&&!this.elements.this_container.contains(e.target)&&this.elements.this_container.classList.contains("open")&&this.toggle_dropdown(!0)})),this.loaded=!0},set_terminals:function(e){for(let t=0;t<e.length;t++)e[t].distance=!1;this.terminals=e},set_selected:function(){this.selected={id:this.params.selected_terminal,text:this.elements.org_field.options[this.elements.org_field.selectedIndex].text,distance:!1}},set_search_value:function(e){this.elements.this_search.value=e.trim(),this.geo_suggest(this.elements.this_search.value)},activate_autoselect:function(){if(""==this.params.selected_terminal){let e=this.elements.this_list.querySelector("li:not(.city)");this.mark_element_list_selected(e)}},update_element_dropdown:function(){"text"in this.selected&&(this.elements.this_dropdown.innerHTML=this.selected.text)},show_element_loader:function(e=!1){this.elements.this_loader.style.display=e?"block":"none"},show_element_search_msg:function(e=!1){this.elements.this_search_msg.style.display=e?"block":"none"},show_element_inner_container:function(e=!1){this.elements.this_inner_container.style.display=e?"block":"none"},refresh_element_list:function(){let e,t,s,i,n=0,a=!1;this.clear_element_list();for(let l of this.terminals)e=document.createElement("li"),e.setAttribute("data-id",l.id),e.innerHTML=l.name,"distance"in l&&!1!==l.distance?(s=document.createElement("strong"),i=document.createTextNode(l.distance+"km"),s.appendChild(i),e.innerHTML+=" "+s.outerHTML,n++):this.elements.this_show_more.style.display="none","id"in this.selected&&this.selected.id==l.id&&e.classList.add("selected"),n>this.params.max_show&&(e.style.display="none"),a!=l.city&&(t=document.createElement("li"),t.classList.add("city"),t.innerHTML=l.city,n>this.params.max_show&&(t.style.display="none"),this.elements.this_list.append(t),a=l.city),this.elements.this_list.append(e);this.elements.this_list.querySelectorAll("li:not(.city)").forEach((e=>e.addEventListener("click",(()=>{this.mark_element_list_selected(e)}))))},clear_element_list:function(){for(;this.elements.this_list.firstChild;)this.elements.this_list.removeChild(this.elements.this_list.lastChild)},unmark_element_list_selected:function(){let e=this.elements.this_list.querySelector("li.selected");e&&e.classList.remove("selected")},mark_element_list_selected:function(e){this.unmark_element_list_selected();const t=e.getAttribute("data-id");e.classList.add("selected"),g(this.elements.org_field,t),this.params.selected_terminal=t,this.set_selected(),this.update_element_dropdown(),this.toggle_dropdown(!0)},toggle_dropdown:function(e=!1){this.elements.this_container.classList.contains("open")||e?(this.show_element_inner_container(!1),this.elements.this_container.classList.remove("open")):(this.show_element_inner_container(!0),this.elements.this_container.classList.add("open"))},show_element_all_options:function(){this.elements.this_list.querySelectorAll("li").forEach((e=>{e.style.display="",this.elements.this_show_more.style.display="none"}))},hide_element_all_options:function(){this.elements.this_list.querySelectorAll("li").forEach((e=>{e.style.display="none",this.elements.this_show_more.style.display=""}))},reset_terminals:function(){for(let e=0;e<this.terminals.length;e++)this.terminals[e].distance=!1;this.terminals.sort((function(e,t){return e.city.localeCompare(t.city)||t.name-e.name}))},geo_find_position:async function(e){if(""==e||e.length<3)return this.reset_terminals(),this.show_element_all_options(),this.refresh_element_list(),!1;let t="https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/findAddressCandidates?singleLine="+e+"&sourceCountry="+this.params.country+"&category=&outFields=Postal&maxLocations=1&forStorage=false&f=pjson",s=await(async()=>await v(t))();if("candidates"in s&&s.candidates.length){let e=s.candidates[0];this.sort_list_by_distance(e.location.y,e.location.x),this.refresh_element_list(),this.elements.this_show_more.style.display="",this.params.autoselect&&this.activate_autoselect()}},geo_suggest:async function(e){if(""==e||e.length<3)return this.reset_terminals(),this.show_element_all_options(),this.refresh_element_list(),this.show_element_loader(!1),e.length&&(this.elements.this_search_msg.innerHTML=this.translations.too_short,this.show_element_search_msg(!0)),!1;let t="https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/suggest?text="+e+"&f=pjson&sourceCountry="+this.params.country+"&maxSuggestions=1",s=await(async()=>await v(t))();"suggestions"in s&&s.suggestions.length?this.geo_find_position(s.suggestions[0].text):(this.elements.this_search_msg.innerHTML=this.translations.not_found,this.show_element_search_msg(!0),this.hide_element_all_options()),this.show_element_loader(!1)},sort_list_by_distance:function(e,t){let s;for(let i=0;i<this.terminals.length;i++)s=this.calculate_distance(e,t,this.terminals[i].coords.lat,this.terminals[i].coords.lng),this.terminals[i].distance=s.toFixed(2);this.terminals.sort(((e,t)=>{let s=e.distance,i=t.distance;return parseFloat(s)<parseFloat(i)?-1:parseFloat(s)>parseFloat(i)?1:0}))},calculate_distance:function(e,t,s,i){let n=this.to_radius(s-e),a=this.to_radius(i-t);e=this.to_radius(e),s=this.to_radius(s);let l=Math.sin(n/2)*Math.sin(n/2)+Math.sin(a/2)*Math.sin(a/2)*Math.cos(e)*Math.cos(s);return 2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l))*6371},to_radius:e=>e*Math.PI/180,error:function(e){console.error("OMNIVA CUSTOM SELECT:",e)}}),b=JSON.parse('{"apiVersion":2,"name":"omnivalt/terminal-selection-checkout","version":"1.0.0","title":"Omniva terminal selection","category":"woocommerce","description":"Allow to add components for Omniva shipping method","parent":["woocommerce/checkout-shipping-methods-block"],"supports":{"html":false,"align":false,"multiple":false,"reusable":false},"attributes":{"lock":{"type":"object","default":{"remove":true,"move":true}},"text":{"type":"string","default":""}},"textdomain":"omnivalt"}');(0,e.registerCheckoutBlock)({metadata:b,component:({checkoutExtensionData:e,extensions:r})=>{const c="omnivalt_terminal",{setExtensionData:_}
1=e,[p,v]=(0,s.useState)({country:"LT",postcode:""}),[g,b]=(0,s.useState)(null),[E,S]=(0,s.useState)([]),[k,L]=(0,s.useState)({}),[T,M]=(0,s.useState)([]),[C,x]=(0,s.useState)([{label:d.select_terminal,value:""}]),[O,A]=(0,s.useState)(u(!1)),[P,F]=(0,s.useState)({title:d.title_terminal,label:d.select_terminal,error:d.error_terminal}),[I,j]=(0,s.useState)(""),[D,N]=(0,s.useState)(""),[q,H]=(0,s.useState)({provider:"unknown",type:"unknown"}),[V,$]=(0,s.useState)(""),B=(0,s.useRef)(null),R=(0,s.useRef)(null),G=y(),U=w();h("Block show",O),h("Terminals list",T),h("Destination",g),h("Map values",p),h("Selected terminal",I),h("Selected rate ID",D),h("Omniva dynamic data",k),(0,s.useCallback)((0,a.debounce)(((e,t,s)=>{_(e,t,s)}),1e3),[_]);const{setValidationErrors:z,clearValidationError:Y}=(0,n.useDispatch)("wc/store/validation"),J=(0,n.useSelect)((e=>e("wc/store/validation").getValidationError(c))),W=(0,n.useSelect)((e=>e("wc/store/cart").getCartData().shippingRates));return(0,s.useEffect)((()=>{W.length?S((e=>{if(!e.length)return[];let t=[];for(let s=0;s<e.length;s++)if(e[s].shipping_rates)for(let i=0;i<e[s].shipping_rates.length;i++)t.push(e[s].shipping_rates[i]);return t})(W)):m("Empty param: shippingRates")}),[W]),(0,s.useEffect)((()=>{A(u(!1)),m("Received "+E.length+" active rates:",E);for(let e=0;e<E.length;e++)E[e].rate_id&&E[e].selected&&(o(E[e].rate_id)&&E[e].selected&&A(u(!0)),N(E[e].rate_id))}),[E]),(0,s.useEffect)((()=>{O.value&&b(((e,t=!0)=>{if(m("Getting destination..."),!e.length)return m("Failed to get destination because shipping rates is empty"),null;let s=[];for(let t=0;t<e.length;t++)e[t].destination&&s.push(e[t].destination);return s.length?t?(m("First destination",s[0]),s[0]):(m("Destinations",s),s):(m("Failed to get destination"),null)})(W))}),[O]),(0,s.useEffect)((()=>{g&&""!=g.country.trim()?v({country:g.country,postcode:g.postcode}):v({country:"LT",postcode:""})}),[g]),(0,s.useEffect)((()=>{var e,t;o(D)?D?(e=p.country,t=D,fetch(`${l().ajax_url}?action=omnivalt_get_dynamic_data&country=${e}&method=${t}`,{method:"GET",credentials:"same-origin",headers:{"Content-Type":"application/json"}}).then((e=>e.json())).catch((e=>(console.error("Error fetching terminals:",e),[])))).then((e=>{if(e.data){const t=e.data;L(t)}else m("Failed to get dynamic Omniva data")})):m("Skipped retrieving dynamic Omniva data because the value of the selected rate ID is not received"):m("The selected delivery method is not delivery to the Omniva terminal")}),[p,D]),(0,s.useEffect)((()=>{if(f(k))return void m("Skipped getting Terminals because the Omniva dynamic data is empty");if(!1===k.terminals_type)return void m("The selected delivery method does not have a terminals");const e="terminals_type"in k?k.terminals_type:"omniva";var t,s;(t=p.country,s=e,fetch(`${l().ajax_url}?action=omnivalt_get_terminals&country=${t}&type=${s}`,{method:"GET",credentials:"same-origin",headers:{"Content-Type":"application/json"}}).then((e=>e.json())).catch((e=>(console.error("Error fetching terminals:",e),[])))).then((e=>{e.data?M(e.data):m("Failed to get terminals list")}))}),[k]),(0,s.useEffect)((()=>{const e={title:d.title_terminal,label:d.select_terminal,error:d.error_terminal};!f(k)&&"terminals_type"in k&&"post"==k.terminals_type&&(e.title=d.title_post,e.label=d.select_post,e.error=d.error_post),F(e)}),[k]),(0,s.useEffect)((()=>{if(!T.length)return void m("Skipped updating terminals block because the terminals list is empty");m("Updating terminal selection options...");const e=[{label:P.label,value:""}];for(let t=0;t<T.length;t++)e.push({label:T[t].name,value:T[t].id});x(e)}),[T]),(0,s.useEffect)((()=>{if(R.current){""!==R.current.innerHTML&&(m("Removing previous custom field/map..."),(e=>{for(;e.firstChild;)e.removeChild(e.lastChild)})(R.current));let e=null,t=!0;"show_map"in l()&&(e=l().show_map,t=l().autoselect,H({provider:"provider"in k?k.provider:"unknown",type:"terminals_type"in k?k.terminals_type:"unknown"})),!0===e?(m("Initializing TMJS map..."),G.load_data({org_field:B.current,map_container:R.current,terminals_type:k.terminals_type,provider:k.provider,country:p.country,map_icon:k.map_icon,selected_terminal:I}),G.init(T),G.set_search_value(p.postcode)):!1===e?(m("Initializing terminal select field..."),U.load_data({org_field:B.current,custom_container:R.current,provider:k.provider,terminals_type:k.terminals_type,country:p.country,selected_terminal:I,autoselect_terminal:t}),U.set_terminals(T),U.init(),U.set_search_value(p.postcode)):m("Failed to get map display param")}else m("Failed to get container for custom field/map")}),[C]),(0,s.useEffect)((()=>{J&&(m("Clearing terminal validation error..."),Y(c),$("")),o(D)&&(_("omnivalt","selected_terminal",I),""===I&&(m("Terminal not selected. Adding terminal validation error..."),z({[c]:{message:P.error,hidden:!1}}),$("error")))}),[_,I,D]),(0,s.useEffect)((()=>{_("omnivalt","selected_rate_id",D)}),[_,D]),O.value?(0,t.createElement)("div",{className:`omnivalt-terminal-select-container provider-${q.provider} type-${q.type} ${V}`},(0,t.createElement)("div",{id:"omnivalt-terminal-container-org",className:"omnivalt-org-select"},(0,t.createElement)(i.SelectControl,{id:"omnivalt-terminal-select-field",label:P.title,value:I,options:C,onChange:e=>j(e),ref:B}),J?.hidden||""!==I?null:(0,t.createElement)("div",{className:"wc-block-components-vali
1dation-error omnivalt-terminal-error"},(0,t.createElement)("span",null,J?.message))),(0,t.createElement)("div",{id:"omnivalt-terminal-container-map",className:"omnivalt-map-select",ref:R},(0,t.createElement)("div",{class:"omnivalt-loader"}))):(0,t.createElement)(t.Fragment,null)}})})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.