define(["jquery","knockout","viewModels/guidedNavigationViewModel","pubsub","navigation","pageLayout/search","viewportHelper","ccResourceLoader!global/OCS_BFService"],function(e,t,n,r,i,s,o,u){"use strict";var a;return{filterYears:t.observableArray([]),filterKilometers:t.observableArray([{text:"0",value:0}]),filterPrices:t.observableArray([{text:"0",value:0}]),filterYearFrom:t.observable(),filterYearTo:t.observable(),filterKilometerFrom:t.observable(),filterKilometerTo:t.observable(),filterPriceFrom:t.observable(),filterPriceTo:t.observable(),filterMaskPriceFrom:t.observable(),filterMaskPriceTo:t.observable(),filterBrand:t.observable(),customFilters:t.observableArray(),displayRefineResults:t.observable(!1),showFiltersBox:t.observable({Modelo:t.observable(!1),Marca:t.observable(!1)}),filterBoxModelo:t.observable(!1),salesManOption:t.observable(!1),searchMarca:t.observable(""),searchModelo:t.observable(""),branchOfficesDictionary:t.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(i){a=i;for(var s=1;s<16;s++)a.filterKilometers().push({text:s*10+".000",value:s*1e4});a.filterKilometers().push({text:"Máximo",value:3e5});for(var s=(new Date).getFullYear()-15;s<=((new Date).getMonth()>8?(new Date).getFullYear()+1:(new Date).getFullYear());s++)a.filterYears().push(s);for(var s=1;s<=10;s++)a.filterPrices().push({text:s*5+".000.000",value:s*5e6});a.filterPrices().push({text:"Máximo",value:1e8}),e(document).on("click","#CC-guidedNavigation-accordionSection .dropdown-menu",function(e){e.stopPropagation()}),i.guidedNavigationViewModel=t.observable(),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),i.guidedNavigationViewModel(new n(i.maxDimensionCount(),i.maxRefinementCount(),i.locale())),e.Topic(r.topicNames.SEARCH_RESULTS_FOR_CATEGORY_UPDATED).subscribe(function(e){!this.navigation||this.navigation.length==0?i.displayRefineResults(!1):i.displayRefineResults(!0)}),e.Topic(r.topicNames.SEARCH_FAILED_TO_PERFORM).subscribe(function(e){i.displayRefineResults(!1)}),e.Topic(r.topicNames.SEARCH_RESULTS_UPDATED).subscribe(function(e){a.showSalesManOptions(),this.navigation&&this.navigation.length>0||this.breadcrumbs&&this.breadcrumbs.refinementCrumbs&&this.breadcrumbs.refinementCrumbs.length>0?i.displayRefineResults(!0):i.displayRefineResults(!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.filterMaskPriceFrom.subscribe(function(e){a.validateInputPriceFilter()}),a.filterMaskPriceTo.subscribe(function(e){a.validateInputPriceFilter()}),a.filterBrand.subscribe(function(e){e&&e.checkedValue&&e.checkedValue(!0)}),a.guidedNavigationViewModel().dimensions.subscribe(function(){a.showFiltersBox().Marca(!1),a.guidedNavigationViewModel().dimensions().forEach(function(e){e.dimensionName=="product.x_marca"&&e.refinements().length>0&&a.showFiltersBox().Marca(!0)})}),a.guidedNavigationViewModel().allRefinementCrumbs.subscribe(function(){a.showFiltersBox().Modelo(!1);if(a.guidedNavigationViewModel()&&a.guidedNavigationViewModel().allRefinementCrumbs()){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(t){var n=e("div[id*='itemListMarca-']").length>0?e("div[id*='itemListMarca-']"):[],r=0;for(var i=0;i0?e("div[id*='itemListModelo-']"):[],r=0;for(var i=0;i0&&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(t[1].split("+")[1])),a.filterPriceTo(Number(t[1].split("+")[2])),a.executefilterPrice(!0)):t[1].split(" ").length>1?(a.filterPriceFrom(Number(t[1].split(" ")[1])),a.filterPriceTo(Number(t[1].split(" ")[2])),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()=="sm"||o.viewportDesignation()=="md"||o.viewportDesignation()=="lg")&&(u.utils.removeCache("FROM_NSR"),a.customFilters().forEach(function(e){a.customFilters.remove(e)}),a.resetCustomFilterValues())},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={id:"price",type:"Nf",subtype:"BTWN",name:"product.listPrice",parameter1:a.filterPriceFrom()?a.filterPriceFrom():0,parameter2:a.filterPriceTo()?a.filterPriceTo():1e8};a.createUpdateFilter(t,e)},blockYearsSelectOptions:function(){e("#select-filterYearTo option").each(function(){e(this).removeAttr("disabled"),e(this).attr("value")<=a.filterYearFrom()&&e(this).attr("disabled","disabled")}),e("#select-filterYearFrom option").each(function(){e(this).removeAttr("disabled"),e(this).attr("value")>=a.filterYearTo()&&e(this).attr("disabled","disabled")})},blockKilometersSelectOptions:function(){e("#select-filterKilometersTo option").each(function(){e(this).removeAttr("disabled"),e(this).attr("value")<=a.filterKilometerFrom()&&e(this).attr("disabled","disabled")}),e("#select-filterKilometersFrom option").each(function(){e(this).removeAttr("disabled"),e(this).attr("value")>=a.filterKilometerTo()&&e(this).attr("disabled","disabled")})},blockPriceSelectOptions:function(){e("#select-filterPriceTo option").each(function(){e(this).removeAttr("disabled"),e(this).attr("value")<=a.filterPriceFrom()&&e(this).attr("disabled","disabled")}),e("#select-filterPriceFrom option").each(function(){e(this).removeAttr("disabled"),e(this).attr("value")>=a.filterPriceTo()&&e(this).attr("disabled","disabled")})},validateInputPriceFilter:function(){a.filterMaskPriceFrom()&&a.filterPriceFrom(a.filterMaskPriceFrom().replace(".","").replace(".","").replace(".","")),a.filterMaskPriceTo()&&a.filterPriceTo(a.filterMaskPriceTo().replace(".","").replace(".","").replace(".","")),parseInt(a.filterPriceFrom())>parseInt(a.filterPriceTo())?(e("#filterPriceSubmitButton").attr("disabled","disabled"),e("#filterPriceToInput").addClass("invalid"),e("#invalidMessageFilterPriceTo").removeClass("hidden")):(e("#filterPriceSubmitButton").removeAttr("disabled"),e("#filterPriceToInput").removeClass("invalid"),e("#invalidMessageFilterPriceTo").addClass("hidden"))},blockPricesSelectOptions:function(){e("#select-filterPriceTo option").each(function(){e(this).removeAttr("disabled"),e(this).attr("value")0&&r.split("||").filter(function(e){return e.includes(n)}).forEach(function(e){s+=e+"||"}),(s+t).slice(0,-2)},convertClass:function(e){return e.replace("product.","")},hideCategory:function(e){var t=["SUVs","Automóviles","Comerciales","Lexus Usados","Lexus Seminuevos"];return t.indexOf(e.label)!==-1},hideCollapsables:function(){e("#CC-guidedNavigation-collapseList-a-x_marca").collapse("toggle"),e("#CC-guidedNavigation-collapseList-a-x_agno").collapse("toggle"),e("#CC-guidedNavigation-collapseList-a-x_listPrice").collapse("toggle");for(var t=0;t<=20;t++)e("#CC-guidedNavigation-collapseList-"+t).hide(),e("#refinamiento-icon-"+t).text("keyboard_arrow_down");e(".panel-collapse").on("show.bs.collapse",function(){e(this).attr("arrow-filter-id")&&e(this).attr("arrow-filter-id").indexOf("mobile")==-1&&e("#"+e(this).attr("arrow-filter-id")).text("expand_less")}),e(".panel-collapse").on("hide.bs.collapseshow.bs.collapse",function(){e(this).attr("arrow-filter-id")&&e(this).attr("arrow-filter-id").indexOf("mobile")==-1&&e("#"+e(this).attr("arrow-filter-id")).text("keyboard_arrow_down")}),e(".ocs-refinement-title").click(function(){var t=e(this).attr("idtap");e("#CC-guidedNavigation-collapseList-"+t).toggle(),e("#CC-guidedNavigation-collapseList-"+t).is(":visible")?e("#refinamiento-icon-"+t).text("keyboard_arrow_up"):e("#refinamiento-icon-"+t).text("expand_more")}),e(".x_agno").each(function(t,n){e(this).text(e(this).text().replace(".0",""))})},showFilterOptions:function(t){e("#"+t).is(":visible")?e("#"+t).hide(1e3):e("#"+t).show(1e3)},clearAllRefinementsCustom:function(){a.customFilters([]),a.guidedNavigationViewModel().clearAllRefinements(),a.resetCustomFilterValues(),location.href="/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)},showSalesManOptions:function(){var e=new URL(window.location.origin+"/searchresults"+window.location.search),t=e.searchParams.get("Ntt")?e.searchParams.get("Ntt"):"";t==="vendedor"?(a.salesManOption(!0),sessionStorage.setItem("salesManOption","true"),i.goTo("/comprar-seminuevo-precio-promocion-chile/autos-usados")):sessionStorage.getItem("salesManOption")==="true"&&a.salesManOption(!0)},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}}})