"use strict";!function(t){DRTS.Location=DRTS.Location||{},DRTS.Location.textfield=DRTS.Location.textfield||function(e){var a=t(e);if(a.length){var o,s=a.find(".drts-location-text-input"),n=a.find(".drts-location-text-center"),i=a.find(".drts-location-text-viewport"),l=a.find(".drts-location-text-zoom"),c=a.find(".drts-location-text-radius"),g=c.hasClass("drts-location-text-radius-slider"),d=function(){g?c.data("ionRangeSlider").reset():c.val("")};if(s.length){var r={suggest_place:void 0===a.data("suggest-place")||(a.data("suggest-place")||!1),suggest_place_header:a.data("suggest-place-header")||"",suggest_place_footer:a.data("suggest-place-footer")||"",suggest_place_icon:a.data("suggest-place-icon")||"fas fa-map-pin",suggest_place_country:a.data("suggest-place-country")||null,suggest_place_minlength:a.data("suggest-place-minlength")||1,suggest_location:a.data("suggest-location"),suggest_location_header:a.data("suggest-location-header")||"",suggest_location_icon:a.data("suggest-location-icon")||"",suggest_location_url:a.data("suggest-location-url")||null,suggest_location_count:a.data("suggest-location-count")||null,suggest_location_parents:a.data("suggest-location-parents")||!1,geolocation:void 0===a.data("geolocation")||(a.data("geolocation")||!1)},u=a.find(".drts-location-text-term-id"),p=a.find(".drts-location-text-taxonomy"),v=a.find(".drts-clear").css("visibility",s.val().length>0?"visible":"hidden"),h=[];if(r.suggest_location&&r.suggest_location_url){var _={},f=new Bloodhound({datumTokenizer:Bloodhound.tokenizers.obj.whitespace("title","pt"),queryTokenizer:Bloodhound.tokenizers.whitespace,prefetch:{url:r.suggest_location_url}});r.suggest_location_header&&(_.header="<h4>"+r.suggest_location_header+"</h4>"),_.suggestion=function(e){var a=e.title;r.suggest_location_count&&(a+=" ("+(e.count||"0")+")"),r.suggest_location_parents&&e.pt&&(a+=" - "+e.pt.join(" > "));var o,s=t("<div/>").html(t("<span />").text(a));return e.icon_src?o=t("<img/>").attr("class","drts-icon drts-icon-sm").attr("src",e.icon_src):r.suggest_location_icon&&(o=t("<i/>").attr("class","drts-icon drts-icon-sm "+r.suggest_location_icon)),o&&s.prepend(o),s[0].outerHTML},h.push({name:r.suggest_location,source:function(t,e,a){t.length>0&&f.search(t,e,a)},display:r.suggest_location_parents?function(t){return t.pt?t.pt.join(" > ")+" > "+t.title:t.title}:"title",templates:_,limit:a.data("suggest-location-num")||100})}if(r.suggest_place){var m={};r.suggest_place_header&&(m.header=t("<h4/>").text(r.suggest_place_header)[0].outerHTML),r.suggest_place_icon&&(m.suggestion=function(e){var a=t("<div/>");return a.append(t("<i/>").attr("class","drts-icon drts-icon-sm "+r.suggest_place_icon)).append(t("<span/>").text(e.text)),a[0].outerHTML}),r.suggest_place_footer&&(m.footer=t("<div/>").attr("class","tt-footer").css({"text-align":"right",margin:"0 5px 3px"}).html(r.suggest_place_footer)[0].outerHTML),h.push({name:"place",display:"text",templates:m,source:function(t,e,a){t.length<r.suggest_place_minlength||DRTS.Location.api.getSuggestions(t,a)}})}if(r.geolocation&&navigator.geolocation&&("https:"===document.location.protocol||"localhost"===document.location.hostname)){var y=function(){var t=!1;s.addClass("drts-ajax-loading"),navigator.geolocation.getCurrentPosition((function(e){s.removeClass("drts-ajax-loading"),t=o=!0,DRTS.Location.api.reverseGeocode([e.coords.latitude,e.coords.longitude],(function(t){s.val(t.address).typeahead("val",t.address),p.val(""),u.val(""),i.val(""),l.val(""),g||c.val()&&!(c.val()<5)||c.val(c.data("default-radius")>5?c.data("default-radius"):5),v.css("visibility",s.val().length>0?"visible":"hidden");var a=e.coords.latitude+","+e.coords.longitude;a!==n.val()&&(n.val(a),s.trigger("change"))}),(function(t){DRTS.flash(t.message,"danger")}))}),(function(e){s.removeClass("drts-ajax-loading"),t||1!==e.code&&DRTS.flash(e.message,"danger"),console.log(e.message+" ("+e.code+")")}),{enableHighAccuracy:!0,timeout:1e4,maximumAge:1/0})};h.push({name:"geolocate",source:function(t,e){o||e([{content:""}])},display:"content",templates:{suggestion:function(){var e=t("<i/>").attr("class","drts-icon drts-icon-sm fas fa-location-arrow");return t("<div/>").html(t("<span/>").text(a.data("geolocation-text")||"Current location")).prepend(e)[0].outerHTML}}})}else a.addClass("drts-location-no-geolocation");h.length?(s.typeahead({highlight:!0,minLength:0},h),s.on("typeahead:select",(function(t,e,c){if(n.val(""),i.val(""),l.val(""),o=!1,g||d(),c===r.suggest_location)p.val(r.suggest_location),u.val(e.id);else if("place"===c)if(p.val(""),u.val(""),e.latlng)n.val(e.latlng[0]+","+e.latlng[1]);else{var h=function(t,e){n.val(t.join(",")),e&&i.val(e.join(","))},_=function(t){console.log(t)};DRTS.Location.api.geocodeSuggestion&&a.data("suggest-place-geocode")?DRTS.Location.api.geocodeSuggestion(e,h,_):DRTS.Location.api.geocode(e.text,h,_)}else"geolocate"===c&&y();v.css("visibility",s.val().length>0?"visible":"hidden")})).on("keyup",(function(t){13!==t.keyCode&&27!==t.keyCode&&32!==t.keyCode&&(p.val(""),u.val(""),n.val(""),i.val(""),l.val(""),g||d(),v.css("visibility",s.val().length>0?"visible":"hidden")),o=!1})).on("typeahead:open",(function(){s.closest(".twitter-typeahead").addClass("twitter-typeahead-open")})).on("typeahead:close",(function(){s.closest(".twitter-typeahead").removeClass("twitter-typeahead-open")})),v.click((function(){p.val(""),u.val(""),n.val(""),i.val(""),l.val(""),g||d(),v.css("visibility","hidden"),s.typeahead("val","").focus().trigger("change"),o=!1,s.typeahead("open")}))):(s.bind("keyup",(function(t){13!==t.keyCode&&27!==t.keyCode&&32!==t.keyCode&&v.css("visibility",s.val().length>0?"visible":"hidden")})),v.click((function(){v.css("visibility","hidden"),s.val("").focus().trigger("change")}))),g&&c.on("change",(function(){l.val()||i.val("")}))}a.on("entity_reset_form_field.sabai",(function(){s.length&&(h.length?s.typeahead("val",""):s.val(""),p.val(""),u.val("")),n.val(""),i.val(""),l.val(""),d()}))}}}(jQuery);