!function(){"use strict";var t="undefined"!=typeof globalThis&&globalThis||"undefined"!=typeof self&&self||void 0!==t&&t,e="URLSearchParams"in t,n="Symbol"in t&&"iterator"in Symbol,i="FileReader"in t&&"Blob"in t&&function(){try{return new Blob,!0}catch(t){return!1}}(),r="FormData"in t,s="ArrayBuffer"in t;if(s)var o=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],a=ArrayBuffer.isView||function(t){return t&&o.indexOf(Object.prototype.toString.call(t))>-1};function l(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(t)||""===t)throw new TypeError('Invalid character in header field name: "'+t+'"');return t.toLowerCase()}function u(t){return"string"!=typeof t&&(t=String(t)),t}function c(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return n&&(e[Symbol.iterator]=function(){return e}),e}function d(t){this.map={},t instanceof d?t.forEach((function(t,e){this.append(e,t)}),this):Array.isArray(t)?t.forEach((function(t){this.append(t[0],t[1])}),this):t&&Object.getOwnPropertyNames(t).forEach((function(e){this.append(e,t[e])}),this)}function h(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function f(t){return new Promise((function(e,n){t.onload=function(){e(t.result)},t.onerror=function(){n(t.error)}}))}function p(t){var e=new FileReader,n=f(e);return e.readAsArrayBuffer(t),n}function m(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function y(){return this.bodyUsed=!1,this._initBody=function(t){var n;this.bodyUsed=this.bodyUsed,this._bodyInit=t,t?"string"==typeof t?this._bodyText=t:i&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:r&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:e&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():s&&i&&((n=t)&&DataView.prototype.isPrototypeOf(n))?(this._bodyArrayBuffer=m(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):s&&(ArrayBuffer.prototype.isPrototypeOf(t)||a(t))?this._bodyArrayBuffer=m(t):this._bodyText=t=Object.prototype.toString.call(t):this._bodyText="",this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):e&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},i&&(this.blob=function(){var t=h(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){if(this._bodyArrayBuffer){var t=h(this);return t||(ArrayBuffer.isView(this._bodyArrayBuffer)?Promise.resolve(this._bodyArrayBuffer.buffer.slice(this._bodyArrayBuffer.byteOffset,this._bodyArrayBuffer.byteOffset+this._bodyArrayBuffer.byteLength)):Promise.resolve(this._bodyArrayBuffer))}return this.blob().then(p)}),this.text=function(){var t,e,n,i=h(this);if(i)return i;if(this._bodyBlob)return t=this._bodyBlob,e=new FileReader,n=f(e),e.readAsText(t),n;if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var e=new Uint8Array(t),n=new Array(e.length),i=0;i<e.length;i++)n[i]=String.fromCharCode(e[i]);return n.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},r&&(this.formData=function(){return this.text().then(E)}),this.json=function(){return this.text().then(JSON.parse)},this}d.prototype.append=function(t,e){t=l(t),e=u(e);var n=this.map[t];this.map[t]=n?n+", "+e:e},d.prototype.delete=function(t){delete this.map[l(t)]},d.prototype.get=function(t){return t=l(t),this.has(t)?this.map[t]:null},d.prototype.has=function(t){return this.map.hasOwnProperty(l(t))},d.prototype.set=function(t,e){this.map[l(t)]=u(e)},d.prototype.forEach=function(t,e){for(var n in this.map)this.map.hasOwnProperty(n)&&t.call(e,this.map[n],n,this)},d.prototype.keys=function(){var t=[];return this.forEach((function(e,n){t.push(n)})),c(t)},d.prototype.values=function(){var t=[];return this.forEach((function(e){t.push(e)})),c(t)},d.prototype.entries=function(){var t=[];return this.forEach((function(e,n){t.push([n,e])})),c(t)},n&&(d.prototype[Symbol.iterator]=d.prototype.entries);var v=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function b(t,e){if(!(this instanceof b))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');var n,i,r=(e=e||{}).body;if(t instanceof b){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new d(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,r||null==t._bodyInit||(r=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=e.credentials||this.credentials||"same-origin",!e.headers&&this.headers||(this.headers=new d(e.headers)),this.method=(n=e.method||this.method||"GET",i=n.toUpperCase(),v.indexOf(i)>-1?i:n),this.mode=e.mode||this.mode||null,this.signal=e.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&r)throw new TypeError("Body not allowed for GET or HEAD requests");if(this._initBody(r),!("GET"!==this.method&&"HEAD"!==this.method||"no-store"!==e.cache&&"no-cache"!==e.cache)){var s=/([?&])_=[^&]*/;if(s.test(this.url))this.url=this.url.replace(s,"$1_="+(new Date).getTime());else{this.url+=(/\?/.test(this.url)?"&":"?")+"_="+(new Date).getTime()}}}function E(t){var e=new FormData;return t.trim().split("&").forEach((function(t){if(t){var n=t.split("="),i=n.shift().replace(/\+/g," "),r=n.join("=").replace(/\+/g," ");e.append(decodeURIComponent(i),decodeURIComponent(r))}})),e}function w(t,e){if(!(this instanceof w))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');e||(e={}),this.type="default",this.status=void 0===e.status?200:e.status,this.ok=this.status>=200&&this.status<300,this.statusText=void 0===e.statusText?"":""+e.statusText,this.headers=new d(e.headers),this.url=e.url||"",this._initBody(t)}b.prototype.clone=function(){return new b(this,{body:this._bodyInit})},y.call(b.prototype),y.call(w.prototype),w.prototype.clone=function(){return new w(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new d(this.headers),url:this.url})},w.error=function(){var t=new w(null,{status:0,statusText:""});return t.type="error",t};var g=[301,302,303,307,308];w.redirect=function(t,e){if(-1===g.indexOf(e))throw new RangeError("Invalid status code");return new w(null,{status:e,headers:{location:t}})};var L=t.DOMException;try{new L}catch(t){(L=function(t,e){this.message=t,this.name=e;var n=Error(t);this.stack=n.stack}).prototype=Object.create(Error.prototype),L.prototype.constructor=L}function T(e,n){return new Promise((function(r,o){var a=new b(e,n);if(a.signal&&a.signal.aborted)return o(new L("Aborted","AbortError"));var l=new XMLHttpRequest;function c(){l.abort()}l.onload=function(){var t,e,n={status:l.status,statusText:l.statusText,headers:(t=l.getAllResponseHeaders()||"",e=new d,t.replace(/\r?\n[\t ]+/g," ").split("\r").map((function(t){return 0===t.indexOf("\n")?t.substr(1,t.length):t})).forEach((function(t){var n=t.split(":"),i=n.shift().trim();if(i){var r=n.join(":").trim();e.append(i,r)}})),e)};n.url="responseURL"in l?l.responseURL:n.headers.get("X-Request-URL");var i="response"in l?l.response:l.responseText;setTimeout((function(){r(new w(i,n))}),0)},l.onerror=function(){setTimeout((function(){o(new TypeError("Network request failed"))}),0)},l.ontimeout=function(){setTimeout((function(){o(new TypeError("Network request failed"))}),0)},l.onabort=function(){setTimeout((function(){o(new L("Aborted","AbortError"))}),0)},l.open(a.method,function(e){try{return""===e&&t.location.href?t.location.href:e}catch(t){return e}}(a.url),!0),"include"===a.credentials?l.withCredentials=!0:"omit"===a.credentials&&(l.withCredentials=!1),"responseType"in l&&(i?l.responseType="blob":s&&a.headers.get("Content-Type")&&-1!==a.headers.get("Content-Type").indexOf("application/octet-stream")&&(l.responseType="arraybuffer")),!n||"object"!=typeof n.headers||n.headers instanceof d?a.headers.forEach((function(t,e){l.setRequestHeader(e,t)})):Object.getOwnPropertyNames(n.headers).forEach((function(t){l.setRequestHeader(t,u(n.headers[t]))})),a.signal&&(a.signal.addEventListener("abort",c),l.onreadystatechange=function(){4===l.readyState&&a.signal.removeEventListener("abort",c)}),l.send(void 0===a._bodyInit?null:a._bodyInit)}))}function x(t){return"window"in t&&t.window===t?t:"nodeType"in(e=t)&&e.nodeType===document.DOCUMENT_NODE&&t.defaultView||!1;var e}function O(t){var e="pageXOffset"===t?"scrollLeft":"scrollTop";return function(n,i){var r=x(n);if(void 0===i)return r?r[t]:n[e];r?r.scrollTo(r[t],i):n[e]=i}}T.polyfill=!0,t.fetch||(t.fetch=T,t.Headers=d,t.Request=b,t.Response=w);var A=O("pageXOffset"),_=O("pageYOffset");function j(t){var e=function(t){return t&&t.ownerDocument||document}(t),n={top:0,left:0,height:0,width:0},i=e&&e.documentElement;return i&&function(t,e){return t.contains?t.contains(e):t.compareDocumentPosition?t===e||!!(16&t.compareDocumentPosition(e)):void 0}(i,t)?(void 0!==t.getBoundingClientRect&&(n=t.getBoundingClientRect()),n={top:n.top+_(i)-(i.clientTop||0),left:n.left+A(i)-(i.clientLeft||0),width:n.width,height:n.height}):n}var B,P={linear:function(t){return t},easeInQuad:function(t){return t*t},easeOutQuad:function(t){return t*(2-t)},easeInOutQuad:function(t){return t<.5?2*t*t:(4-2*t)*t-1},easeInCubic:function(t){return t*t*t},easeOutCubic:function(t){return--t*t*t+1},easeInOutCubic:function(t){return t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1},easeInQuart:function(t){return t*t*t*t},easeOutQuart:function(t){return 1- --t*t*t*t},easeInOutQuart:function(t){return t<.5?8*t*t*t*t:1-8*--t*t*t*t},easeInQuint:function(t){return t*t*t*t*t},easeOutQuint:function(t){return 1+--t*t*t*t*t},easeInOutQuint:function(t){return t<.5?16*t*t*t*t*t:1+16*--t*t*t*t*t}},C=function(t){return parseFloat(t)},U=function(t){return t.indexOf("px")>=0?"px":t.indexOf("%")>=0?"%":t.indexOf("em")>=0?"em":t.indexOf("rem")>=0?"rem":""},k=function(t,e,n){void 0===n&&(n=400);for(var i=[],r=3;r<arguments.length;r++)i[r-3]=arguments[r];var s,o,a=!1,l="linear";if(1===i.length&&"string"==typeof i[0]?l=i[0]:1===i.length&&i[0]instanceof Function?s=i[0]:i.length>1&&"string"==typeof i[0]?(l=i[0],s=i[1],o=i[2]):i.length>1&&i[0]instanceof Function&&(s=i[0],o=i[1]),!P[l]||P[l]instanceof Function==!1)throw new Error("The easing ".concat(l," does not exist, please use one of the following: ").concat(Object.keys(P).join(", ")),P);var u,c,d=window.getComputedStyle(t),h=Object.entries(e).reduce((function(t,e){var n=e[0],i=e[1];return t.push({property:n,propUnit:U(i),propStart:C(d.getPropertyValue(n)),propFinish:C(i),get difference(){return this.propFinish-this.propStart}}),t}),[]),f=function(e){if(a)o&&s&&s instanceof Function&&s();else{if(u||(u=e),(c=e-u)>n)return h.forEach((function(e){t.style.setProperty(e.property,e.propFinish+e.propUnit)})),void(s&&s instanceof Function&&s());requestAnimationFrame(f);var i=P[l](1/n*c);h.forEach((function(e){t.style.setProperty(e.property,e.difference*i+e.propStart+e.propUnit)}))}};return requestAnimationFrame(f),function(){a=!0}},S=function(){function t(t,e){var n=this;this.items=[],this.isString=function(t){return"[object String]"===Object.prototype.toString.call(t)},this.items=[],this.parent=e,this.element=document.createElement("ul");var i=this.parent,r=i.options,s=i.input;if(this.isString(t)){var o=[];t.split(",").map((function(t){var e=t.split(":");2==e.length?0==e[1].indexOf(s.value)&&o.push({value:e[0],label:e[1]}):1==e.length&&0==t.indexOf(s.value)&&o.push({value:t,label:t})})),o.map((function(t){var e=t.label,i=t.value,r=document.createElement("li");r.classList.add("sf-lnk"),r.innerHTML=e,r.setAttribute("data-value",i),n.element.appendChild(r),n.items.push(r)}))}else Object.keys(t).map((function(e){t[e].map((function(t){var e=t.all,i=t.class_name,r=t.template,s=t.title;if(e&&e.length){if(s){var o=document.createElement("li");o.classList.add("sf-header"),o.innerText=s,n.element.appendChild(o)}var a=document.createElement("li"),l=document.createElement("div");l.classList.add("sf-result-container");var u=document.createElement("ul");e.map((function(t){var e=document.createElement("li");e.classList.add("sf-lnk",i),e.innerHTML=n.replaceResults(t,r),u.appendChild(e),n.items.push(e)})),l.appendChild(u),a.appendChild(l),n.element.appendChild(a)}}))}));if(!r.callback){var a=AjaxyLiveSearchSettings.more;a=(a=(a=(a=a.replace(/{search_value_escaped}/g,"".concat(s.value))).replace(/{search_url_escaped}/g,r.searchUrl.replace("%s",encodeURI(s.value)))).replace(/{search_value}/g,"".concat(s.value))).replace(/{total}/g,this.items.length);var l=document.createElement("li");l.classList.add("sf-lnk","sf-more"),0==this.items.length&&l.classList.add("sf-selected"),l.innerHTML=a,this.element.appendChild(l),this.items.push(l)}this.loadLiveEvents(r.callback)}return t.prototype.loadLiveEvents=function(t){var e=this;this.items.map((function(t){t.addEventListener("mouseover",(function(n){e.items.map((function(e){e!=t&&e.classList.remove("sf-selected")})),t.classList.add("sf-selected")}))})),t&&this.items.map((function(n){n.addEventListener("click",(function(i){try{window[t](n,e)}catch(i){alert(i)}}))})),window.addEventListener("keydown",(function(n){if("none"!=e.parent.mainElem.style.display)if("38"==n.key||"40"==n.key){var i=-1;n.stopPropagation(),n.preventDefault(),e.items.some((function(t,e){return!!t.classList.contains("sf-selected")&&(i=e,!0)})),"40"==n.key?i+1<e.items.length&&e.items[i+1]&&(e.items.map((function(t){return t.classList.remove("sf-selected")})),e.items[i+1].classList.add("sf-selected")):"38"==n.key&&(i-1>0&&e.items[i-1]?(e.items.map((function(t){return t.classList.remove("sf-selected")})),e.items[i-1].classList.add("sf-selected")):(e.items.map((function(t){return t.classList.remove("sf-selected")})),e.items[0].classList.add("sf-selected")))}else if("27"==n.key)e.parent.mainElem.style.display="none";else if("13"==n.key){var r=e.parent.mainElem.querySelector("li.sf-loadingselected a"),s=r?r.href:null;if(s&&""!=s)return t?window[t](r,e):window.location.href=s,!1}}))},t.prototype.replaceResults=function(t,e){for(var n in t)e=e.replace(new RegExp("{"+n+"}","g"),t[n]);return e},t}(),D=function(){function t(t,e){if(this.input=null,this.timeout=null,this.options=null,this.defaults={delay:500,leftOffset:0,topOffset:5,text:"Search For",iwidth:180,width:315,ajaxUrl:"",ajaxData:!1,searchUrl:"",expand:!1,callback:!1,rtl:!1,search:!1},this.input=document.querySelector(t),this.input){this.timeout=null,this.options=Object.assign(this.defaults,e),this.attr({placeholder:e.text,autocomplete:"off"},this.input),this.mainElem=document.createElement("div"),this.mainElem.classList.add("sf-container"),this.options.rtl&&this.mainElem.classList.add("sf-rtl"),this.mainElem.style.position="absolute",this.mainElem.style.display="none",this.mainElem.style.width="".concat(e.width),this.mainElem.style.zIndex="9999";var n=document.createElement("div");n.classList.add("sf-sb-cont");var i=document.createElement("div");i.classList.add("sf-sb-top");var r=document.createElement("div");r.classList.add("sf-sb-bottom"),n.appendChild(i),this.resultsElem=document.createElement("div"),this.resultsElem.classList.add("sf-results"),this.valElem=document.createElement("div"),this.valElem.classList.add("sf-val"),this.resultsElem.appendChild(this.valElem),n.appendChild(this.resultsElem),n.appendChild(r),this.mainElem.appendChild(n),document.body.appendChild(this.mainElem),this.loadEvents()}else console.warn("Ajaxy Live Search can't find input ".concat(t))}return t.prototype.attr=function(t,e){Object.keys(t).map((function(n){e.setAttribute(n,t[n])}))},t.prototype.loader=function(t){var e=document.createElement("ul"),n=document.createElement("li");n.classList.add("sf-lnk","sf-more","sf-selected");var i=document.createElement("a");i.classList.add("sf-loading"),i.href=this.options.searchUrl.replace("%s",encodeURI(t)),n.appendChild(i),e.appendChild(n),this.valElem.innerHTML="",this.valElem.appendChild(e)},t.prototype.loadResults=function(){var t=this;if(""!=this.input.value){this.loader(this.input.value),this.mainElem.style.display="block",this.adjustPosition();var e=new FormData;if(e.append("action","ajaxy_sf"),e.append("value",this.input.value),this.options.ajaxData&&window[this.options.ajaxData]&&(e=window[this.options.ajaxData](e)),this.options.search){var n=new S(this.options.search,this);this.valElem.innerHTML="",this.valElem.appendChild(n.element),this.mainElem.style.display="block"}else fetch(this.options.ajaxUrl,{body:e,method:"post"}).then((function(e){e.json().then((function(e){t.parseResults(e)})).catch((function(e){t.parseResults([])}))})).catch((function(e){t.parseResults([])}))}else this.mainElem.style.display="none"},t.prototype.adjustPosition=function(){var t=this.bounds(this.input,this.options);if(!t||"none"==this.mainElem.style.display)return this.mainElem.style.display="none",!1;Math.ceil(t.left)+parseInt(this.options.width,10)>window.innerWidth&&(this.mainElem.style.width="".concat(window.innerWidth-t.left-20,"px")),this.options.rtl?(this.mainElem.style.top="".concat(t.bottom,"px"),this.mainElem.style.left="".concat(t.right,"px"),this.mainElem.style.right="auto"):(this.mainElem.style.top="".concat(t.bottom,"px"),this.mainElem.style.left="".concat(t.left,"px"),this.mainElem.style.right="auto")},t.prototype.parseResults=function(t){var e=new S(t,this);this.valElem.innerHTML="",this.valElem.appendChild(e.element),this.mainElem.style.display="block"},t.prototype.bounds=function(t,e){var n=j(t);if(n)return{top:n.top,left:n.left+e.leftOffset,bottom:n.top+t.clientHeight+e.topOffset,right:n.left-this.mainElem.clientWidth+t.clientWidth}},t.prototype.loadEvents=function(){var t=this;document.addEventListener("click",(function(){t.mainElem.style.display="none"})),window.addEventListener("resize",(function(){"none"!=t.mainElem.style.display&&t.adjustPosition()})),window.addEventListener("scroll",(function(){"none"!=t.mainElem.style.display&&t.adjustPosition()})),this.input.addEventListener("keyup",(function(e){"38"!=e.key&&"40"!=e.key&&"13"!=e.key&&"27"!=e.key&&"39"!=e.key&&"37"!=e.key&&(null!=t.timeout&&clearTimeout(t.timeout),t.mainElem.classList.add("sf-focused"),t.timeout=setTimeout((function(){t.loadResults()}),t.options.delay))})),this.input.addEventListener("focus",(function(){t.input.classList.add("sf-focused"),t.options.expand>0&&k(t.input,{width:t.options.iwidth},500)})),this.input.addEventListener("blur",(function(){t.input.classList.remove("sf-focused"),t.options.expand>0&&k(t.input,{width:t.options.expand},500)}))},t}();B=function(){AjaxyLiveSearchSettings.boxes.map((function(t){new D(t.selector,t.options)}))},"loading"!=document.readyState?B():document.addEventListener("DOMContentLoaded",B)}();
