define(["knockout","viewModels/guidedNavigationViewModel","CCi18n","ccConstants","navigation","pubsub","viewportHelper","ccResourceLoader!global/OCS_BFService"],function(e,t,n,r,i,s,o,u){"use strict";var a;return{disableCheckbox:e.observable(!1),checkFilter:function(e){a.disableCheckbox(!0),e.checkedValue(!e.checkedValue())},filterYears:e.observableArray([]),filterKilometers:e.observableArray([{text:"0",value:0}]),filterPrices:e.observableArray([{text:"0",value:0}]),filterYearFrom:e.observable(),filterYearTo:e.observable(),filterKilometerFrom:e.observable(),filterKilometerTo:e.observable(),filterPriceFrom:e.observable(),filterPriceTo:e.observable(),filterBrand:e.observable(),customFilters:e.observableArray(),displayRefineResults:e.observable(!1),showFiltersBox:e.observable({Modelo:e.observable(!1),Marca:e.observable(!1)}),salesManOption:e.observable(!1),searchMarca:e.observable(""),searchModelo:e.observable(""),branchOfficesDictionary:e.observable({"Av. La Florida 8954, La Florida - Santiago":"Av.La Florida","Av. La Florida 8934":"Av. La Florida 2","Av. Vicuña Mackenna 7781, La Florida - Santiago":"La Florida","Camino a Melipilla 9160, Maipú - Santiago":"Maipú","Camino a Melipilla 9160, Maipú – Santiago":"Maipú 2","Av. La Florida 9510, La Florida - Santiago":"Enrique Olivares","Gómez Carreño 3309, Talcahuano - Concepción":"Talcahuano","Paicavi 2222, Concepción - Concepción":"Paicaví","Paicavi 2222, Concepción – Concepción":"Paicaví 2","Gran Avenida 5020, San Miguel":"San Miguel","Av. Las Condes 10498, Vitacura - Santiago":"Estoril","Av. Vicuña Mackenna 1157, Santiago - Santiago":"Vicuña Mackenna","Pedro Aguirre Cerda 821, San pedro de la Paz":"San Pedro","Av. Jose Miguel Carrera 7711, La Cisterna - Santiago":"Gran Avenida","Av. Chacabuco 183, Concepción - Concepción":"Chacabuco","Av. Chacabuco 183":"Chacabuco 2","Av. las Condes 11568, Vitacura - Santiago":"San Damián","Av. Jose Alcalde Delano 11255, Lo Barnechea - Santiago":"La Dehesa","Arturo Prat 320, Concepción - Concepción":"Prat","Av. Las Condes 11800, Vitacura - Santiago":"Black Label","Avenida Américo Vespucio Express 2451, Cerrillos, Santiago.":"Car Shopping","Pronto Disponible":"Pronto Disponible","Avenida Departamental 1485, La Florida":"Departamental"}),onLoad:function(n){a=n;for(var r=1;r<16;r++)a.filterKilometers().push({text:r*10+".000",value:r*1e4});a.filterKilometers().push({text:"Máximo",value:3e5});for(var r=(new Date).getFullYear()-15;r<=((new Date).getMonth()>8?(new Date).getFullYear()+1:(new Date).getFullYear());r++)a.filterYears().push(r);for(var r=1;r<=10;r++)a.filterPrices().push({text:r*5+".000.000",value:r*5e6});a.filterPrices().push({text:"Máximo",value:1e8}),$(document).on("click","#CC-guidedNavigation-collapseList-a-x_brand-model_mobile .dropdown-menu",function(e){e.stopPropagation()}),a.guidedNavigationViewModel=e.observable(),a.guidedNavigationViewModel(new t(n.maxDimensionCount(),n.maxRefinementCount(),n.locale())),a.isExpanded=e.observable(!1),a.isNavigationVisible=e.observable(!1),a.filterYearFrom(a.filterYears()[0]),a.filterYearTo(a.filterYears()[a.filterYears().length-1]),a.filterKilometerFrom(a.filterKilometers()[0].value),a.filterKilometerTo(a.filterKilometers()[a.filterKilometers().length-1].value),a.filterPriceFrom(a.filterPrices()[0].value),a.filterPriceTo(a.filterPrices()[a.filterPrices().length-1].value),$.Topic(s.topicNames.SEARCH_RESULTS_FOR_CATEGORY_UPDATED).subscribe(function(e){!this.navigation||this.navigation.length==0?n.displayRefineResults(!1):n.displayRefineResults(!0),a.hideCollapsables()}),$.Topic(s.topicNames.SEARCH_FAILED_TO_PERFORM).subscribe(function(e){n.displayRefineResults(!1),a.hideCollapsables()}),$.Topic(s.topicNames.SEARCH_RESULTS_UPDATED).subscribe(function(e){this.navigation&&this.navigation.length>0||this.breadcrumbs&&this.breadcrumbs.refinementCrumbs&&this.breadcrumbs.refinementCrumbs.length>0?n.displayRefineResults(!0):n.displayRefineResults(!1),a.hideCollapsables(),a.disableCheckbox(!1)}),a.filterYearFrom.subscribe(function(e){a.blockYearsSelectOptions()}),a.filterYearTo.subscribe(function(e){a.blockYearsSelectOptions()}),a.filterKilometerFrom.subscribe(function(e){a.blockKilometersSelectOptions()}),a.filterKilometerTo.subscribe(function(e){a.blockKilometersSelectOptions()}),a.filterPriceFrom.subscribe(function(e){a.blockPriceSelectOptions()}),a.filterPriceTo.subscribe(function(e){a.blockPriceSelectOptions()}),a.filterBrand.subscribe(function(e){e&&e.checkedValue&&($("html, body").css("overflow-y","auto"),e.checkedValue(!0))}),n.hideRefinements=function(){n.isNavigationVisible(!1),$("html, body").css("overflow-y","auto"),$("#CC-overlayedGuidedNavigation").hasClass("CC-overlayedGuidedNavigation-mobileView")&&$("#CC-overlayedGuidedNavigation").removeClass("CC-overlayedGuidedNavigation-mobileView");if(n.guidedNavigationViewModel().dimensions()&&n.guidedNavigationViewModel().dimensions().length>0)for(var e=0;e0&&a.showFiltersBox().Marca(!0)})}),a.guidedNavigationViewModel().allRefinementCrumbs.subscribe(function(){a.guidedNavigationViewModel().allRefinementCrumbs().length===0&&a.showFiltersBox().Modelo(!1);var e=a.guidedNavigationViewModel().allRefinementCrumbs().find(function(e){return e.label=="Autos Usados"});if(e){var t=a.guidedNavigationViewModel().allRefinementCrumbs().indexOf(e);a.guidedNavigationViewModel().allRefinementCrumbs().splice(t,1)}a.guidedNavigationViewModel().allRefinementCrumbs().forEach(function(e){e.dimensionName=="product.x_marca"&&a.showFiltersBox().Modelo(!0)})}),a.searchMarca.subscribe(function(e){var t=$("div[id*='itemListMobileMarca-']").length>0?$("div[id*='itemListMobileMarca-']"):[],n=0;for(var r=0;r0?$("div[id*='itemListMobileModelo-']"):[],n=0;for(var r=0;r0&&t.forEach(function(e){var t=e.split("|"),n={id:t[0].split(".")[1],type:"Nf",subtype:t[0].split("+")[0],name:t[0],parameter1:t[1].split(" ")[1],parameter2:t[1].split(" ")[2]};if(t[0].split(".")[1]=="x_agno"){var r=t[1].split("+")[1]?t[1].split("+")[1]:t[1].split(" ")[1],i=t[1].split("+")[2]?t[1].split("+")[2]:t[1].split(" ")[2];r&&i&&(a.filterYearFrom(parseInt(r)),a.filterYearTo(parseInt(i)),a.executefilterYear2(!0))}else t[0].split(".")[1]=="listPrice"?t[1].split("+").length>1?(a.filterPriceFrom(Number(String(t[1].split("+")[1]).replace(/\./g,""))),a.filterPriceTo(Number(String(t[1].split("+")[2]).replace(/\./g,""))),a.executefilterPrice(!0)):t[1].split(" ").length>1?(a.filterPriceFrom(Number(String(t[1].split(" ")[1]).replace(/\./g,""))),a.filterPriceTo(Number(String(t[1].split(" ")[2]).replace(/\./g,""))),a.executefilterPrice(!0)):console.error("BF_guidedNavigation: Error parse number"):t[0].split(".")[1]=="x_kilometraje"&&(t[1].split("+").length>1?(a.filterKilometerFrom(Number(t[1].split("+")[1])),a.filterKilometerTo(Number(t[1].split("+")[2])),a.executefilterKilometers(!0)):t[1].split(" ").length>1?(a.filterKilometerFrom(Number(t[1].split(" ")[1])),a.filterKilometerTo(Number(t[1].split(" ")[2])),a.executefilterKilometers(!0)):console.error("BF_guidedNavigation: Error parse number"));a.executeFilter()})}u.utils.cache("FROM_NSR")&&o.viewportDesignation()=="xs"&&(u.utils.removeCache("FROM_NSR"),a.customFilters().forEach(function(e){a.customFilters.remove(e)}),a.resetCustomFilterValues(),a.handleHideRefinements())},convertClass:function(e){return e.replace("product.","")},handleHideRefinements:function(e,t){return this.hideRefinements(),$("#CC-productList-refineResults").focus(),!1},collapseDimension:function(e,t){e.isExpanded()?(e.isExpanded(!1),e.ariaLabelText("expandText")):(e.isExpanded(!0),e.ariaLabelText("collapseText"))},hideCategory:function(e){var t=["SUVs","Automóviles","Comerciales","Lexus Usados","Lexus Seminuevos"];return t.indexOf(e.label)!==-1},tDebug:function(e){console.log("tDebug"),console.log(e)},executefilterYear2:function(e){var t={id:"x_agno",type:"Nf",subtype:"BTWN",name:"product.x_agno",parameter1:a.filterYearFrom(),parameter2:a.filterYearTo()};a.createUpdateFilter(t,e)},executefilterKilometers:function(e){var t={id:"x_kilometraje",type:"Nf",subtype:"BTWN",name:"product.x_kilometraje",parameter1:a.filterKilometerFrom(),parameter2:a.filterKilometerTo()};a.createUpdateFilter(t,e)},executefilterPrice:function(e){var t=a.filterPriceFrom()?a.filterPriceFrom():0,n=a.filterPriceTo()?a.filterPriceTo():1e8,r={id:"price",type:"Nf",subtype:"BTWN",name:"product.listPrice",parameter1:Number(String(t).replace(/\./g,"")),parameter2:Number(String(n).replace(/\./g,""))};a.createUpdateFilter(r,e)},blockYearsSelectOptions:function(){$("#select-filterYearTo-mb option").each(function(){$(this).removeAttr("disabled"),$(this).attr("value")<=a.filterYearFrom()&&$(this).attr("disabled","disabled")}),$("#select-filterYearFrom-mb option").each(function(){$(this).removeAttr("disabled"),$(this).attr("value")>=a.filterYearTo()&&$(this).attr("disabled","disabled")})},blockKilometersSelectOptions:function(){$("#select-filterKilometersTo-mb option").each(function(){$(this).removeAttr("disabled"),$(this).attr("value")<=a.filterKilometerFrom()&&$(this).attr("disabled","disabled")}),$("#select-filterKilometersFrom-mb option").each(function(){$(this).removeAttr("disabled"),$(this).attr("value")>=a.filterKilometerTo()&&$(this).attr("disabled","disabled")})},blockPriceSelectOptions:function(){$("#select-filterPriceTo-mb option").each(function(){$(this).removeAttr("disabled"),$(this).attr("value")<=a.filterPriceFrom()&&$(this).attr("disabled","disabled")}),$("#select-filterPriceFrom-mb option").each(function(){$(this).removeAttr("disabled"),$(this).attr("value")>=a.filterPriceTo()&&$(this).attr("disabled","disabled")})},createUpdateFilter:function(e,t){var n=!1;a.customFilters().forEach(function(t){t.id==e.id&&(a.customFilters.replace(t,e),n=!0)}),n||a.customFilters.push(e),t||($("html, body").css("overflow-y","auto"),a.executeFilter())},removeRefinementCustom:function(e){a.customFilters.remove(e),a.executeFilter()},executeFilter:function(){if(o.viewportDesignation()=="xs"){var e=new URL(window.location.origin+"/searchresults"+window.location.search),n=window.location.search.split("&").filter(function(e){return e.indexOf("N=")!=-1})[0];n=n?n.split("=")[1]:a.guidedNavigationViewModel().categoryDimensionId(),e.searchParams.set("N",n),e.searchParams.set("Nrpp","12"),e.searchParams.set("suppressResults","true"),e.searchParams.set("searchType","guided"),e.searchParams.set("type","search"),e.searchParams.set("Ns","sku.activePrice|1");var r="";a.customFilters().forEach(function(e){e.subtype=="BTWN"&&(r+=e.name+"|"+e.subtype+"+"+e.parameter1+"+"+e.parameter2+"||")}),r=r.slice(0,-2),e.searchParams.set("Nf",r);var s=window.location.pathname+window.location.search;s=decodeURIComponent(s).replace("sku.activePrice|0","").replace("sku.activePrice|1","");var u=decodeURIComponent("/searchresults"+e.search).replace("sku.activePrice|0","").replace("sku.activePrice|1","");s!=u&&(!window.location.search||e.search.indexOf(window.location.search)==-1||r)&&(t.prototype.createSpinner(),i.goTo("/searchresults"+decodeURIComponent(e.search)))}},hideCollapsables:function(){a.guidedNavigationViewModel()&&a.guidedNavigationViewModel().allRefinementCrumbs()&&a.guidedNavigationViewModel().allRefinementCrumbs().forEach(function(e){e.dimensionName=="product.x_marca"&&a.showFiltersBox().Modelo(!0)})},clearAllRefinementsCustom:function(){a.customFilters([]),a.guidedNavigationViewModel().clearAllRefinements(),a.resetCustomFilterValues(),i.goTo("/comprar-seminuevo-precio-promocion-chile/autos-usados")},resetCustomFilterValues:function(){a.filterYearFrom(a.filterYears()[0]),a.filterYearTo(a.filterYears()[a.filterYears().length-1]),a.filterKilometerFrom(a.filterKilometers()[0].value),a.filterKilometerTo(a.filterKilometers()[a.filterKilometers().length-1].value),a.filterPriceFrom(a.filterPrices()[0].value),a.filterPriceTo(a.filterPrices()[a.filterPrices().length-1].value)},filterTagTranslate:function(e){var t={x_kilometraje:"km:",x_agno:"Año:",price:"Precio:",3e5:"Máximo",1e8:"Máximo",Comerciales:"Camionetas / Comerciales"},n=Intl.NumberFormat("de-DE",{currency:"EUR"});return!t[e]&&typeof e=="number"&&e>0&&(e<2e3||e>2024)&&(e=n.format(e)),t[e]?t[e]:e}}})