function preventSubmit(e){e.preventDefault()}function whenMapReady(e){if(!window.googleApisPromise&&!window.google)throw new Error("Google Maps API not loaded");return!window.googleApisPromise&&window.google?(e(),Promise.resolve()):(window.googleApisPromise.then(e),window.googleApisPromise)}function setFilterSummary(){var e=getFiltersSummary();$(".result-text .filters-summary").html(`<span class="summary-title">match your filters:</span> <span>${e}</span>`),$(".search-text .filters-summary").html(`<span class="summary-title">matching your filters:</span> <span>${e}</span>`)}function getFiltersSummary(){var e="";return $(".top-filters__left select").each(function(t){var o=getFormattedValue($(this).val(),$(this).attr("id"),e);o&&(e+=t>0?", "+o:o)}),e}function useFilterFunctionality(){window.isSearchPage=$("body.search").length>0,window.isSearchPage?setFilterSummary():$(".filters-summary-wrapper").remove()}function getParameters(){var e={},t=$("#type-select").val();t&&(e.type=t);var o=$("#style-select").val();if(o&&o.length>0){var s=[];for(let e=0;e<o.length;e++)o[e]&&s.push(o[e]);e.propertyType=s}var a=$("#city-select").val();if(a&&a.length>0){var i=[];for(let e=0;e<a.length;e++)a[e]&&i.push(a[e]);e.city=i}var r=$("#neighborhood-select").val();if(r&&r.length>0){var n=[];for(let e=0;e<r.length;e++)r[e]&&n.push(r[e]);e.neighborhood=n}var l=$("#minBeds").val();l&&(e.minBeds=l);var c=$("#minBaths").val();c&&(e.minBaths=c);var p=$("#price-select").val();p&&(e.price=p);var h=$("#minPriceSelect").val();h&&(e.minPrice=h);var d=$("#maxPriceSelect").val();d&&(e.maxPrice=d);var g=Cookies.get("sortBy");return g&&(e.sortBy=g),e}function getCookieParameters(){var e={},t=Cookies.get("type");t&&(e.type=t);var o=Cookies.get("propertyType")?Cookies.get("propertyType").split(","):"";if(o&&o.length>0){var s=[];for(let e=0;e<o.length;e++)o[e]&&s.push(o[e]);e.propertyType=s}var a=Cookies.get("city")?Cookies.get("city").split(","):"";if(a&&a.length>0){var i=[];for(let e=0;e<a.length;e++)a[e]&&i.push(a[e]);e.city=i}var r=Cookies.get("neighborhood")?Cookies.get("neighborhood").split(","):"";if(r&&r.length>0){var n=[];for(let e=0;e<r.length;e++)r[e]&&n.push(r[e]);e.neighborhood=n}var l=Cookies.get("minBeds");l&&(e.minBeds=l);var c=Cookies.get("minBaths");c&&(e.minBaths=c);var p=Cookies.get("price");p&&(e.price=p);var h=Cookies.get("sortBy");return h&&(e.sortBy=h),e}function getFormattedValue(e,t,o){var s=Array.isArray(e)?e.join(", "):e;return e&&("type-select"===t?s="sale"===s?"For sale":"lease"===s?"For lease":"recently-sold"===s?"Recently sold":"Recently leased":"minBeds"===t?s+="+ bedrooms":"minBaths"===t?s+="+ baths":"city-select"!==t&&"neighborhood-select"!==t||(s="",e.forEach(function(t,a){t&&(0===a?s+=o.includes(", in")?" "+t:"in "+t:a===e.length-1?s+=" and "+t:s+=", "+t)}))),s}window.isSearchPage=!1,whenMapReady(function(){window.mapObject&&0!==$("#map_right_listing").length&&!["/favourites","/my-listings"].includes(window.location.pathname.toLowerCase())||(window.mapObject=new google.maps.Map(document.getElementById("bar-map")),$.ajax({type:"GET",url:"/locations",contentType:"application/json; charset=utf-8",success:function(e){window.locations=e},error:function(e){console.log(e)}}));var e={bounds:new google.maps.LatLngBounds(new google.maps.LatLng(41.242,29.215),new google.maps.LatLng(40.518,30.37))};window.placeService=new google.maps.places.PlacesService(window.mapObject),window.atocompleteService=new google.maps.places.AutocompleteService(e),useFilterFunctionality();var t=[],o=$("input[name='skeyword']"),s=$(".top-search__results .search-properties li");o.on("input",function(){var e=$(this).val(),o="Clear Filters"===$(".top-search__results .apply").eq(0).text(),a={input:e,componentRestrictions:{country:"ca"},fields:["address_components","geometry","icon","name"],bounds:new google.maps.LatLngBounds(new google.maps.LatLng(42.47209690919285,-82.386474609375),new google.maps.LatLng(44.95702412512118,-77.54150390625))};if(window.atocompleteService.getPlacePredictions(a,function(e,t){if(t===google.maps.places.PlacesServiceStatus.OK){console.log(e);var o="";const t=["neighborhood","political","geocode"],a=["route"];e=(e=e.filter(e=>{return e.types.filter(e=>t.indexOf(e)>-1).length>0})).filter(e=>{return 0===e.types.filter(e=>a.indexOf(e)>-1).length});for(var s=0;s<e.length;s++)o+=`<li data-place_id="${e[s].place_id}">${e[s].description}</li>`;$(".top-search__results .google-places ul").html(o),o&&$(".top-search__results").addClass("show")}}),e&&e.length>=3){$(".search-text").show(),$(".result-text").hide(),s.show().unmark(),$(".loader-block").show();var i={q:e,status:$("#status-select").val()};if(o){var r=getParameters();i={...i,...r}}if(!1===window.isSearchPage){r=getCookieParameters();i={...i,...r}}if($(".top-search__results .search-properties li").remove(),t.push($.ajax({type:"POST",url:"/autocomplete",contentType:"application/json; charset=utf-8",data:JSON.stringify(i),success:function(o){t.shift(),0===t.length&&($(".loader-block").hide(),0===o.total?$(".view-all").hide():$(".view-all").show(),$(".search-text").hide(),$(".result-text").show());var s="";o.listings.forEach(e=>{var t="";t=e.soldPrice?`<span class="price-wrapper ${e.blur}">| <span class="old-price">${e.price}</span><span class="${e.type}">${e.soldPrice} ${"lease"===e.type?'<span class="per_month">month</span>':""}</span></span>`:`<span class="price-wrapper ${e.blur}">| <span class="${e.type}">${e.price} ${"lease"===e.type?'<span class="per_month">month</span>':""}</span></span>`,s+=`\n\t\t\t\t\t\t\t<li style="">\n\t\t\t\t\t\t\t\t<a href="${e.url}">\n\t\t\t\t\t\t\t\t\t<img class="${e.blur}" src="${e.image}" alt="" title="">\n\t\t\t\t\t\t\t\t\t<div>\n\t\t\t\t\t\t\t\t\t\t<h3>${e.title} ${t}</h3>\n\t\t\t\t\t\t\t\t\t\t<p class="${e.blur}">${e.description}</p>\n\t\t\t\t\t\t\t\t\t\t<span class="${e.blur}">${e.footer}</span>\n\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t</a>\n\t\t\t\t\t\t\t</li>\n\t\t\t\t\t\t`}),$(".top-search__results .search-properties").html(s);var a=$(".top-search__results .search-properties li");$(".listings-quantity").text(o.total),a.mark(e,{done:function(){a.not(":has(mark)").hide(),$("#top-search-total").html(o.total+"&nbsp;")}})},error:function(e){0===t.length&&($(".search-text").hide(),$(".result-text").show(),$(".loader-block").hide()),console.log(e)}})),t.length>1){var n=t.shift();n&&n.abort()}}}),o.on("keyup",function(){(this.value.length>=3&&$(".top-search__title, .top-search__results").addClass("show"),0===this.value.length)&&(Cookies.get("keywordsApplied")&&(Cookies.remove("keywordsApplied"),window.isSearchPage&&applyFilter()));$(".top-search-keywords").text($(this).val())}),o.click(function(){this.value.length>=3&&(!0===window.filterChanged&&($("input[name='skeyword']").trigger("input"),window.filterChanged=!1),$(".top-search__results").addClass("show"))}),$(".top-search__results").hover(function(){$(this).addClass("hovered")},function(){$(this).removeClass("hovered")});var a={locality:13,sublocality:14,postal_code:16};function i(e){for(const t of e)if(a[t])return a[t];return 14}$("body").on("click",".google-places li",function(){$(".top-search__results").removeClass("show"),$("input[name=skeyword]").val("");const e={placeId:$(this).data().place_id,fields:["geometry","type","name","address_component"]};window.placeService.getDetails(e,(e,t)=>{if(t===google.maps.places.PlacesServiceStatus.OK&&e&&e.geometry&&e.geometry.location){if(0===$("#map_right_listing").length||["/favourites","/my-listings"].includes(window.location.pathname.toLowerCase())){if(e.types.includes("political")){if(window.locations.cities.indexOf(e.name)>-1)return window.location.href=`/search?city=${e.name}`;if(window.locations.neighborhoods.indexOf(e.name)>-1){const t=e.address_components[1].long_name;return window.locations.cities.indexOf(t)>-1?window.location.href=`/search?city=${t}&neighborhood=${e.name}`:window.location.href=`/search?neighborhood=${e.name}`}}return window.location.href=`/search?location=${e.geometry.location.lat()},${e.geometry.location.lng()},${i(e.types)}`}if($("#city-select option:selected").prop("selected",!1),$("#neighborhood-select option:selected").prop("selected",!1),window.allNeighborhoods.forEach(e=>{$("#neighborhood-select").append($("<option></option>").html(e.name))}),$("#city-select")[0].sumo.reload(),$("#neighborhood-select")[0].sumo.reload(),removePolygons(),e.types.includes("political")){if((a=$(`#city-select option[value="${e.name}"]`).index())>0)return $(`.city-select .options li:eq(${a})`).click();var o=$(`#neighborhood-select option[value="${e.name}"]`).index();if(o>0){var s=window.allNeighborhoods.find(t=>t.name===e.name);if(e.address_components.length>4)if(!(e.address_components.findIndex(e=>e.long_name===s.city)>-1))return window.mapObject.setCenter(e.geometry.location),void window.mapObject.setZoom(i(e.types));const t=e.address_components[1].long_name;var a;return(a=$(`#city-select option[value="${t}"]`).index())>0&&$("#city-select")[0].sumo.selectItem(a),$(`.neighborhood-select .options li:eq(${o})`).click()}}window.mapObject.setCenter(e.geometry.location),window.mapObject.setZoom(i(e.types))}})}),$("body").click(function(e){$(e.target).is(o)||$(".top-search__results").hasClass("hovered")||$(".top-search__results").removeClass("show")}),$(".top-search__results .apply").on("click",function(){"Clear Filters"==$(this).text()?(window.skipMapBounds=!0,$(".top-search__results .apply").text("Apply Filters"),$(".filters-summary").hide()):($(".top-search__results .apply").text("Clear Filters"),$(".filters-summary").show()),$("input[name='skeyword']").trigger("input")}),$(".top-search__links .view-all").on("click",function(){window.viewAll=!0;var e=o.val();Cookies.set("keywordsApplied",!0),Cookies.set("keywords",e),Cookies.set("resetFilters","Apply Filters"===$(".top-search__results .apply").eq(0).text()),$(".top-search__results").removeClass("show"),window.isSearchPage?(window.markersBounds=!0,applyFilter()):(Cookies.set("status",$("#status-select").val()),window.location.href="/")}),$("#status-select").on("change",function(){"A"===$(this).val()?$(".search-status").text("available"):$(".search-status").text("sold/rented"),$("input[name='skeyword']").trigger("input"),o.val().length>=3&&$(".top-search__results").addClass("show")}),$("#status-select-filter").on("click",function(e){var t="Hide Filters"==$(".top-filters__more").text();t?$(".save-search").prop("disabled",!1):$(".save-search").prop("disabled",!0),$(this).toggleClass("active"),$(".top-filters__more").toggleClass("active"),$(".top-filters__left").toggleClass("active"),$(".select-arrow").toggleClass("active"),$(".top-filters__more").text(t?"Show Filters":"Hide Filters")})});