const zpForm=document.getElementById("zp-birthreport-form");var a,b,cityIn=document.getElementById("placein"),zpSubmit=document.getElementById("zp-fetch-birthreport");zpSubmit.setAttribute("disabled",!0),a=this,b=function(){"use strict";function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}function t(e){return"string"==typeof e?document.querySelector(e):e()}function n(e){return e.innerHTML=""}function o(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var n=document.createEvent("CustomEvent");return n.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),n}var s="data-result",r="autoComplete_result",i=t,a=function(e){var t=document.createElement(e.element);return t.setAttribute("id","autoComplete_results_list"),e.container&&e.container(t),e.destination.insertAdjacentElement(e.position,t),t},l=function(e){return"<span class=".concat("autoComplete_highlighted",">").concat(e,"</span>")},u=function(e,t,n){t.forEach(function(o,i){var a=document.createElement(n.element),l=t[i].value[o.key]||t[i].value;a.setAttribute(s,l),a.setAttribute("class",r),a.setAttribute("tabindex","1"),n.content?n.content(o,a):a.innerHTML=o.match||o,e.appendChild(a)})},c=n,d=function(e,o,i,a){var l=o.querySelectorAll(".".concat(r));Object.keys(l).forEach(function(u){["mousedown","keydown"].forEach(function(c){l[u].addEventListener(c,function(l){"mousedown"!==c&&13!==l.keyCode&&39!==l.keyCode||(i({event:l,query:t(e)instanceof HTMLInputElement?t(e).value:t(e).innerHTML,matches:a.matches,results:a.list.map(function(e){return e.value}),selection:a.list.find(function(e){return(e.value[e.key]||e.value)===l.target.closest(".".concat(r)).getAttribute(s)})}),n(o))})})})};o.prototype=window.Event.prototype;var m={CustomEventWrapper:"function"==typeof window.CustomEvent&&window.CustomEvent||o,initElementClosestPolyfill:function(){Element.prototype.matches||(Element.prototype.matches=Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector),Element.prototype.closest||(Element.prototype.closest=function(e){var t=this;do{if(t.matches(e))return t;t=t.parentElement||t.parentNode}while(null!==t&&1===t.nodeType);return null})}};return function(){function n(e){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,n),this.selector=e.selector||"#autoComplete",this.data={src:function(){return"function"==typeof e.data.src?e.data.src():e.data.src},key:e.data.key,cache:void 0===e.data.cache||e.data.cache},this.query=e.query,this.searchEngine="loose"===e.searchEngine?"loose":"strict",this.threshold=e.threshold||0,this.debounce=e.debounce||0,this.resultsList={render:!(!e.resultsList||!e.resultsList.render)&&e.resultsList.render,view:e.resultsList&&e.resultsList.render?a({container:!(!e.resultsList||!e.resultsList.container)&&e.resultsList.container,destination:e.resultsList&&e.resultsList.destination?e.resultsList.destination:i(this.selector),position:e.resultsList&&e.resultsList.position?e.resultsList.position:"afterend",element:e.resultsList&&e.resultsList.element?e.resultsList.element:"ul"}):null},this.sort=e.sort||!1,this.placeHolder=e.placeHolder,this.maxResults=e.maxResults||5,this.resultItem={content:!(!e.resultItem||!e.resultItem.content)&&e.resultItem.content,element:e.resultItem&&e.resultItem.element?e.resultItem.element:"li"},this.noResults=e.noResults,this.highlight=e.highlight||!1,this.onSelection=e.onSelection,this.dataSrc,this.init()}return function(t,n,o){n&&e(t.prototype,n)}(n,[{key:"search",value:function(e,t){var n=this.highlight,o=t.toLowerCase();if("loose"===this.searchEngine){e=e.replace(/ /g,"");for(var s=[],r=0,i=0;i<o.length;i++){var a=t[i];r<e.length&&o[i]===e[r]&&(a=n?l(a):a,r++),s.push(a)}return r===e.length&&s.join("")}if(o.includes(e))return e=new RegExp("".concat(e),"i").exec(t),n?t.replace(e,l(e)):t}},{key:"listMatchedResults",value:function(e){var n=this;return new Promise(function(o){var s=[];e.filter(function(e,t){function o(o){var r=n.search(n.queryValue,e[o]||e);r&&o?s.push({key:o,index:t,match:r,value:e}):r&&!o&&s.push({index:t,match:r,value:e})}if(n.data.key){var r=!0,i=!1,a=void 0;try{for(var l,u=n.data.key[Symbol.iterator]();!(r=(l=u.next()).done);r=!0)o(l.value)}catch(o){i=!0,a=o}finally{try{r||null==u.return||u.return()}finally{if(i)throw a}}}else o()});var r=n.sort?s.sort(n.sort).slice(0,n.maxResults):s.slice(0,n.maxResults);return n.resultsList.render&&(u(n.resultsList.view,r,n.resultItem),function(e,n){var o=t(e),s=n.firstChild;document.onkeydown=function(t){if(t.target.matches(e)){var r=document.activeElement;switch(t.keyCode){case 38:r!==s&&r!==o?r.previousSibling.focus():r===s&&o.focus();break;case 40:r===o&&0<n.childNodes.length?s.focus():r!==n.lastChild&&r.nextSibling.focus()}}}}(n.selector,n.resultsList.view)),o({matches:s.length,list:r})})}},{key:"ignite",value:function(){var e,t,n,o=this,s=this.selector,r=i(s),a=this.query,l=this.placeHolder;function u(e){function t(e,t){r.dispatchEvent(new m.CustomEventWrapper("autoComplete",{bubbles:!0,detail:{event:e,input:n,query:i,matches:t?t.matches:null,results:t?t.list:null},cancelable:!0}))}var n=r instanceof HTMLInputElement?r.value.toLowerCase():r.innerHTML.toLowerCase(),i=o.queryValue=a&&a.manipulate?a.manipulate(n):n,l=o.resultsList.render,u=i.length>o.threshold&&i.replace(/ /g,"").length;if(l){var p=o.onSelection,f=o.resultsList.view;c(f),u?o.listMatchedResults(o.dataSrc).then(function(n){t(e,n),0===n.list.length&&o.noResults&&o.resultsList.render?o.noResults():p&&d(s,f,p,n)}):t(e)}else!l&&u?o.listMatchedResults(o.dataSrc).then(function(n){t(e,n)}):t(e)}l&&r.setAttribute("placeholder",l),r.addEventListener("keyup",(e=function(e){if(o.data.cache)u(e);else{var t=o.data.src();t instanceof Promise?t.then(function(t){o.dataSrc=t,u(e)}):(o.dataSrc=t,u(e))}},t=this.debounce,function(){var o=this,s=arguments;clearTimeout(n),n=setTimeout(function(){return e.apply(o,s)},t)}))}},{key:"init",value:function(){var e=this,t=this.data.src();t instanceof Promise?t.then(function(t){e.dataSrc=t,e.ignite()}):(this.dataSrc=t,this.ignite()),m.initElementClosestPolyfill()}}]),n}()},"object"==typeof exports&&"undefined"!=typeof module?module.exports=b():"function"==typeof define&&define.amd?define(b):a.autoComplete=b();const autoCompletejs=new autoComplete({data:{src:async function(){if(!(cityIn.value.length<2)){const n=zp_strings.u,o=cityIn.value,s=zp_strings.lang,r=await fetch(`https://secure.geonames.org/searchJSON?name_startsWith=${o}&featureClass=P&style=full&maxRows=20&username=${n}&lang=${s}`),i=await r.json();var e=[];if(zpRemoveError(),void 0!==i.status)zpShowError("ERROR "+i.status.value+" - "+i.status.message);else for(var t=0;t<i.geonames.length;t++)e[t]={name:i.geonames[t].name+", "+(i.geonames[t].adminName1?i.geonames[t].adminName1+", ":"")+i.geonames[t].countryName,lat:i.geonames[t].lat,lng:i.geonames[t].lng,zone:i.geonames[t].timezone.timeZoneId};return e}},key:["name"],cache:!1},selector:"#placein",threshold:1,searchEngine:"loose",maxResults:20,resultsList:{render:!0,container:function(e){e.setAttribute("id","autoComplete_results_list")},destination:cityIn,position:"afterend",element:"ul"},resultItem:{content:function(e,t){t.innerHTML=e.match},element:"li"},onSelection:function(e){cityIn.value="",cityIn.setAttribute("placeholder",e.selection.value.name),document.getElementById("place").value=e.selection.value.name,document.getElementById("geo_timezone_id").value=e.selection.value.zone,document.getElementById("zp_lat_decimal").value=e.selection.value.lat,document.getElementById("zp_long_decimal").value=e.selection.value.lng,zpGetOffset()}});function zpGetOffset(){const e=Array.from(new FormData(zpForm),e=>e.map(encodeURIComponent).join("=")).join("&")+"&action=zp_tz_offset",t=new XMLHttpRequest;t.open("POST",zp_strings.ajaxurl),t.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),t.responseType="json",t.onload=function(){200===t.status&&t.response&&(t.response.error?(zpRemoveError(),zpShowError(t.response.error)):null!==t.response.offset_geo&&""!==t.response.offset_geo&&"false"!=t.response.offset_geo&&(zpRemoveError(),document.getElementById("zp-offset-wrap").style.display="block",document.getElementById("zp_offset_geo").value=t.response.offset_geo,document.getElementById("zp-form-tip").style.display="block",zpSubmit.removeAttribute("disabled")))},t.send(e)}function redoOffset(e){if("unknown_time"===e.target.id)e.target.checked&&zpFieldsFilled()&&zpGetOffset();else{if(!["month","day","year","hour","minute"].includes(e.target.id))return;!e.target.options[e.target.selectedIndex].defaultSelected&&zpFieldsFilled()&&zpGetOffset()}}function zpFieldsFilled(){for(var e of["geo_timezone_id","zp_long_decimal","zp_lat_decimal","place","minute","hour","year","day","month"]){var t=document.getElementById(e);if(null===t)return!1;if(0===t.value.length||!t.value.trim()){if(("minute"===e||"hour"===e)&&document.getElementById("unknown_time").checked)continue;return!1}}return!0}function zpRemoveError(){var e=document.querySelector(".ui-state-error");null!==e&&e.parentNode.removeChild(e)}function zpShowError(e){var t=document.createElement("span");t.setAttribute("class","ui-state-error"),t.textContent=e,document.getElementById("zp-birthplace").appendChild(t)}zpSubmit.addEventListener("click",function(e){e.preventDefault();const t=Array.from(new FormData(zpForm),e=>e.map(encodeURIComponent).join("=")).join("&"),n=new XMLHttpRequest;n.open("POST",zp_strings.ajaxurl),n.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),n.responseType="json",n.onload=function(){if(200===n.status&&n.response)if(n.response.error)zpRemoveError(),zpShowError(n.response.error);else{var e=n.response.report.trim();if(e&&"false"!=e){var t=document.getElementById("zp-report-content"),o=document.getElementById("zp-report-wrap");switch(zpRemoveError(),o.style.display="block",t.insertAdjacentHTML("afterbegin",n.response.report),document.getElementById("zp-form-wrap").style.display="none",zp_strings.draw){case"top":document.querySelector(".zp-report-header").insertAdjacentHTML("afterend",n.response.image);break;case"bottom":t.insertAdjacentHTML("beforeend",n.response.image)}window.scrollTo({top:o.offsetTop+70,behavior:"smooth"})}}},n.send(t)}),zpForm.addEventListener("change",redoOffset);