!function(e){const t={slider:null,sliderValue:0,distance:0,init:function(){const n=t;this.slider=e(".store-lists-other-filter-wrap .dokan-geolocation-location-filters .dokan-range-slider"),this.sliderValue=this.slider.prev(".dokan-range-slider-value").find("span"),this.slider.on("input",this.setSliderValue),this.slider.on("change",this.setDistance),e(".store-lists-other-filter-wrap .dokan-geolocation-location-filters .location-address input").on("change",this.buildAddressQuery),n.bindAddressInput(),e(" #dokan-store-listing-filter-wrap .dokan-geolocation-filters-loading").remove()},buildAddressQuery:function(e){const n=t;n.setParam("address",e.target.value),e.target.value||(n.setParam("distance",""),n.setParam("longitude",""),n.setParam("latitude",""))},bindAddressInput:function(){window.google&&google.maps?this.bindeGoogleMap():e('[name="dokan_mapbox_access_token"]').val()&&this.bindMapbox()},bindeGoogleMap:function(){const n=t,o=e(".location-address");n.geocoder=new google.maps.Geocoder;let a=o.find("input");autocomplete=new google.maps.places.Autocomplete(a.get(0)),autocomplete.addListener("place_changed",function(){const e=autocomplete.getPlace();if(e){const t=e.geometry.location;n.latitude=t.lat(),n.longitude=t.lng(),n.setAddress(e.formatted_address)}}),n.navigatorGetCurrentPosition(function(){n.geocoder.geocode({location:{lat:n.latitude,lng:n.longitude}},function(e,t){let o="";"OK"===t&&(o=e[0].formatted_address),n.setAddress(o),a.val(o)})})},bindMapbox:function(){const n=t,o=e(".location-address").find("input"),a=o.get(0),i=new Suggestions(a,[],{minLength:3,limit:3,hideOnBlur:!1});i.getItemValue=function(e){return e.place_name},o.on("change",function(){if(i.selected){const e=i.selected;n.latitude=e.geometry.coordinates[1],n.longitude=e.geometry.coordinates[0],n.setAddress(e.place_name)}});const s=_.debounce(function(e,t){e.cancel&&e.cancel(),n.mapboxGetPlaces(t,function(e){i.update(e)})},250);o.on("input",function(){const t=e(this).val();s(s,t)}),n.navigatorGetCurrentPosition(function(){n.mapboxGetPlaces({lng:n.longitude,lat:n.latitude},function(e){if(e&&e.length){let t=e[0].place_name;n.setAddress(t),o.val(t)}})})},navigatorGetCurrentPosition:function(n){const o=t,a=e(".location-address").find(".locate-icon"),i=a.next();navigator.geolocation&&a.removeClass("dokan-hide").on("click",function(){a.addClass("dokan-hide"),i.removeClass("dokan-hide"),navigator.geolocation.getCurrentPosition(function(e){a.removeClass("dokan-hide"),i.addClass("dokan-hide"),o.latitude=e.coords.latitude,o.longitude=e.coords.longitude,n()},function(){a.removeClass("dokan-hide"),i.addClass("dokan-hide")})})},mapboxGetPlaces:function(t,n){if(!t)return;const o=e('[name="dokan_mapbox_access_token"]').val();t.lng&&t.lat&&(t=t.lng+"%2C"+t.lat);const a="https://api.mapbox.com/geocoding/v5/mapbox.places/"+t+".json?access_token="+o+"&cachebuster="+ +new Date+"&autocomplete=true";e.ajax({url:a,method:"get"}).done(function(e){e.features&&"function"==typeof n&&n(e.features)})},setAddress:function(e){const n=t;if(n.setParam("address",e),!n.distance){let e=0,t=n.slider.val();if(t)e=t;else{const t=parseInt(n.slider.attr("min"),10),o=parseInt(n.slider.attr("max"),10);e=Math.ceil((t+o)/2)}n.setParam("distance",e)}n.setParam("latitude",n.latitude),n.setParam("longitude",n.longitude)},setParam:function(e,t){t?dokan.storeLists.query[e]=t:delete dokan.storeLists.query[e]},setSliderValue:function(e){t.sliderValue.html(e.target.value)},setDistance:function(e){t.setParam("distance",e.target.value)}};t.init()}(jQuery);