(()=>{function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t(e)}function e(t,e){var o=Object.keys(t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(t);e&&(a=a.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),o.push.apply(o,a)}return o}function o(t){for(var o=1;o<arguments.length;o++){var a=null!=arguments[o]?arguments[o]:{};o%2?e(Object(a),!0).forEach(function(e){r(t,e,a[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(a)):e(Object(a)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(a,e))})}return t}function a(t,e){for(var o=0;o<e.length;o++){var a=e[o];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(t,s(a.key),a)}}function n(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(n=function(){return!!t})()}function i(t){return i=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},i(t)}function c(t,e){return c=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},c(t,e)}function r(t,e,o){return(e=s(e))in t?Object.defineProperty(t,e,{value:o,enumerable:!0,configurable:!0,writable:!0}):t[e]=o,t}function s(e){var o=function(e){if("object"!=t(e)||!e)return e;var o=e[Symbol.toPrimitive];if(void 0!==o){var a=o.call(e,"string");if("object"!=t(a))return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==t(o)?o:o+""}!function(e){"use strict";var s=function(){window.JetSmartFilters.filtersList.JetEngineLocationDistance="jet-smart-filters-location-distance",window.JetSmartFilters.filters.JetEngineLocationDistance=function(){function s(o){var a;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,s);var c=o.find(".jsf-location-distance");return r(a=function(e,o,a){return o=i(o),function(e,o){if(o&&("object"==t(o)||"function"==typeof o))return o;if(void 0!==o)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(e)}(e,n()?Reflect.construct(o,a||[],i(e).constructor):o.apply(e,a))}(this,s,[o,c]),"name","location-distance"),r(a,"currentLocationVerbose","Your current location"),r(a,"defaultLocation",null),r(a,"$locationParent",null),r(a,"$locationInput",null),r(a,"$locationDropdown",null),r(a,"$distanceInput",null),r(a,"xhr",!1),r(a,"debounced",!1),r(a,"minAutocompleteRequest",3),a.locationData={},a.$locationParent=c.find(".jsf-location-distance__location"),a.$locationInput=c.find(".jsf-location-distance__location-input"),a.$locationDropdown=c.find(".jsf-location-distance__location-dropdown"),a.$distanceInput=c.find(".jsf-location-distance__distance"),c.data("geolocation-placeholder")&&(a.currentLocationVerbose=c.data("geolocation-placeholder")),a.$distanceInput.on("change",function(t){a.updateLocationData({distance:t.target.value})}),a.defaultLocation=c.data("current-location"),a.defaultLocation&&a.updateLocationData(a.defaultLocation,!0),a.defaultLocation.address&&a.$locationInput.val(a.defaultLocation.address),a.defaultLocation.distance&&a.selectDistance(a.defaultLocation.distance),a.$locationInput.on("keyup",function(t){var e=t.keyCode?t.keyCode:t.which;t.target.value.length?(a.switchClear(!0),a.switchLocate()):(a.switchClear(),a.switchLocate(!0));var o=parseInt(a.minAutocompleteRequest);if((o=isFinite(o)?o:3)>t.target.value.length)a.clearDropdown();else{if(a.updateLocationData({address:t.target.value},!0),13===e)return a.maybeApplyFilter(),void a.clearDropdown();a.debounced&&clearTimeout(a.debounced),a.debounced=setTimeout(a.fillAddressDropdown.bind(a),200,t.target.value)}}),a.$locationDropdown.on("click",".jsf-location-distance__location-dropdown-item",function(t){var o=e(t.target);a.$locationInput.val(o.data("address")),a.clearDropdown(),a.updateLocationData({address:o.data("address"),latitude:0,longitude:0})}),a.$locationParent.on("click",".jsf-location-distance__location-clear",function(t){a.reset()}),a.$locationParent.on("click",".jsf-location-distance__location-locate",function(t){a.switchLocate(),a.switchLoading(!0),navigator.geolocation.getCurrentPosition(function(t){a.switchLoading(),a.$locationInput.val(a.currentLocationVerbose),a.switchClear(!0),a.updateLocationData({address:0,latitude:t.coords.latitude,longitude:t.coords.longitude})})}),e(document).on("click",function(t){e(t.target).closest(".jsf-location-distance__location").length||a.clearDropdown()}),a}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&c(t,e)}(s,window.JetSmartFilters.filters.Search),l=s,(u=[{key:"fillAddressDropdown",value:function(t){var o=this;this.xhr&&this.xhr.abort(),this.xhr=e.ajax({url:window.JetMapListingLocationDistanceFilterData.apiAutocomplete,type:"GET",dataType:"json",data:{query:t}}).done(function(t){if(o.clearDropdown(),t&&t.success){o.$locationDropdown.addClass("is-active");for(var e=0;e<t.data.length;e++){var a=t.data[e].address,n=document.createElement("div");n.classList.add("jsf-location-distance__location-dropdown-item"),n.dataset.address=a,n.innerText=a,o.$locationDropdown.append(n)}}})}},{key:"maybeApplyFilter",value:function(){["ajax","mixed"].includes(this.applyType)&&this.emitFiterApply()}},{key:"reset",value:function(){this.resetLocationData(!1)}},{key:"resetLocationData",value:function(t){this.updateLocationData({},t,["address","longitude","latitude","distance"]),this.clearDistance(),this.clearLocation()}},{key:"setData",value:function(t){this.resetLocationData(!0),t&&this.updateLocationData(o({},t),!0),t&&void 0!==t.address&&(0==t.address&&t.latitude&&t.longitude?this.$locationInput.val(this.currentLocationVerbose):this.$locationInput.val(t.address),this.switchClear(!0),this.switchLocate()),t&&t.distance&&this.selectDistance(t.distance)}},{key:"selectDistance",value:function(t){this.clearDistance(),this.$distanceInput.find('option[value="'+t+'"]').prop("selected",!0).attr("selected",!0)}},{key:"clearDistance",value:function(){this.$distanceInput.find("option[selected]").removeProp("selected").removeAttr("selected")}},{key:"activeValue",get:function(){if(!this.hasLocation()&&!this.locationData.distance)return!1;var t=[];return this.locationData.address&&0!=this.locationData.address?t.push(this.locationData.address):this.locationData.latitude&&this.locationData.longitude&&t.push(this.currentLocationVerbose),t.push(this.locationData.distance+this.locationData.units),t.join(", ")}},{key:"locationDataIsEmpty",value:function(){return!this.locationData||0===Object.keys(this.locationData).length||!this.hasLocation()&&!this.locationData.distance}},{key:"data",get:function(){return this.dataValue&&!this.disabled?o({},this.dataValue):!this.locationDataIsEmpty()&&!this.disabled&&o({},this.locationData)}},{key:"processData",value:function(){this.locationDataIsEmpty?this.dataValue=!1:this.dataValue=o({},this.locationData)}},{key:"clearLocation",value:function(){this.$locationInput.val(""),this.clearDropdown(),this.switchClear(),this.switchLocate(!0)}},{key:"hasLocation",value:function(){return!(!this.locationData||!(this.locationData.address||this.locationData.latitude||this.locationData.longitude))}},{key:"clearDropdown",value:function(){this.$locationDropdown.html("").removeClass("is-active")}},{key:"switchClear",value:function(t){t&&!this.$locationParent.hasClass("jsf-show-clear")?this.$locationParent.addClass("jsf-show-clear"):t||this.$locationParent.removeClass("jsf-show-clear")}},{key:"switchLoading",value:function(t){t&&!this.$locationParent.hasClass("jsf-show-loading")?this.$locationParent.addClass("jsf-show-loading"):t||this.$locationParent.removeClass("jsf-show-loading")}},{key:"switchLocate",value:function(t){navigator.geolocation?t&&!this.$locationParent.hasClass("jsf-show-locate")?this.$locationParent.addClass("jsf-show-locate"):t||this.$locationParent.removeClass("jsf-show-locate"):this.$locationParent.removeClass("jsf-show-locate")}},{key:"updateLocationData",value:function(t,e,o){if(0!==Object.keys(t).length){for(var a in t)this.locationData[a]=t[a];this.locationData.distance||(this.locationData.distance=this.$distanceInput.data("default")),this.locationData.units||(this.locationData.units=this.$distanceInput.data("units"))}if(o)for(var n=0;n<o.length;n++)delete this.locationData[o[n]];e||(this.emitFiterChange(),this.maybeApplyFilter())}}])&&a(l.prototype,u),Object.defineProperty(l,"prototype",{writable:!1}),l;var l,u}()};window.addEventListener("DOMContentLoaded",function(){window.JetSmartFilters&&-1===window.JetSmartFilters.filterNames.indexOf("location-distance")&&window.JetSmartFilters.filterNames.push("location-distance")}),window.JetMapListingGeolocationFilterData&&"jet-smart-filters/before-init"===window.JetMapListingGeolocationFilterData.initEvent?document.addEventListener("jet-smart-filters/before-init",function(t){s()}):window.addEventListener("DOMContentLoaded",function(t){s()})}(jQuery)})();