define(["jquery","knockout","viewModels/productListingViewModelFactory","CCi18n","ccConstants","pubsub","pageLayout/product","storageApi","ccStoreConfiguration","ccResourceLoader!global/OCS_BFService","navigation","ccRestClient","spinner"],function(e,t,n,r,i,s,o,u,a,f,l,c,h){"use strict";var p,d=1,v=!1,m=i.DEFAULT_ITEMS_PER_PAGE,g=0,y="",b,w,E=300,S=300,x=600,T=400,N=300,C="",k="selectedProductsPerRow",L=!1,A=!1;return{productsPerRowArray:t.observableArray([t.observable(!1),t.observable(!1),t.observable(!1),t.observable(!1),t.observable(!1)]),selectedProductsPerRow:t.observable(),displayRefineResults:t.observable(!1),showListViewButton:t.observable(!1),productsSelectedForComparison:t.observableArray([]),showResultsPerPageSection:t.observable(!1),largeDimensions:t.observable("300,300"),mediumDimensions:t.observable("300,300"),imageSizes:[E,S,x,T,N],rowClass:t.observable("items4"),WIDGET_ID:"productListing",mobileSize:300,advertisingCard:t.observable(),gridMode:t.observable("grid"),listProducts:t.observableArray([]),isMobile:t.observable(!1),pricePrice:f.utils.product.parsePrice,onLoad:function(l){p=l,setTimeout(function(){e(document).ready(function(){e(".formatkm").each(function(t,n){e(this).text(e(this).text().toString().replace(/\B(?=(\d{3})+(?!\d))/g,"."))})})},1e3);var c={};l.productTypes&&l.productTypes()&&t.utils.arrayForEach(l.productTypes(),function(e){for(var t=0;t=s/5*4&&l.listingViewModel().incrementPage()},l.scrollHandleOnViewPort=function(){e(window).off("scroll.page"),l.listingViewModel().isLoadOnScroll(!1)},l.productGrid=t.observableArray([]),l.changePageForSearch=function(e){window.scrollTo(0,0),l.productGrid([]),l.listProducts([]),l.listingViewModel().targetPage=1;if(this.parameters.type!=i.PARAMETERS_SEARCH_QUERY)return;this.parameters.page?(l.listingViewModel().pageNumber=parseInt(this.parameters.page),l.listingViewModel().targetPage=parseInt(this.parameters.page)):l.listingViewModel().pageNumber=1,l.listingViewModel().parameters=this.parameters,l.listType()==i.LIST_VIEW_SEARCH&&(l.listingViewModel().recordsPerPage&&l.listingViewModel().recordsPerPage()!=null&&!l.changedViaPagination&&(isNaN(l.productsPerPage())?l.listingViewModel().recordsPerPage(i.DEFAULT_SEARCH_RECORDS_PER_PAGE):l.listingViewModel().recordsPerPage(parseInt(l.productsPerPage()))),l.scrollHandleOnViewPort(),l.listingViewModel().load(1)),l.listingViewModel().paginationType(2)},e.Topic(s.topicNames.PAGE_CHANGED).subscribe(l.getPageUrlData.bind(l)),e.Topic(s.topicNames.PAGE_PAGINATION_CHANGE).subscribe(l.changePage.bind(l)),e.Topic(s.topicNames.PAGE_PAGINATION_CHANGE).subscribe(function(){l.setAdvertisingCard(l)}),e.Topic(s.topicNames.PAGE_PARAMETERS).subscribe(l.changePageForSearch),l.formatProducts=function(e){var t=[],n=e.length;for(var r=0;re&&n0&&(l.listingViewModel().refreshValues==1?(l.productGrid(e),l.listingViewModel().refreshValues=!1):l.productGrid.push.apply(l.productGrid,e))}),l.adjustScrollPosition=function(){if(l.listingViewModel().isCacheEnabled&&l.productGrid()&&l.productGrid().length>1){var t=l.listingViewModel().findCachedResultIndex();t!=undefined&&l.listingViewModel().cachedViewModels[t].scrollPosition>0&&(e("html, body").stop(),e(window).scrollTop(l.listingViewModel().cachedViewModels[t].scrollPosition))}},l.categoryUpdate=function(e){if(!e)return;var t=l.listingViewModel().category();l.listType()!==i.LIST_VIEW_PRODUCTS&&(l.listType(i.LIST_VIEW_PRODUCTS),l.listingViewModel(n.createListingViewModel(l))),(!t||t.id!=e.id||v)&&l.listingViewModel().resetSortOptions_OCS();if(!t||t.id!=e.id||v||!l.listingViewModel().paginationOnly)l.listingViewModel().category(e),l.listingViewModel().clearOnLoad=!0,l.productGrid([]),l.listProducts([]),l.listingViewModel().targetPage=1,l.listingViewModel().load(1),l.listingViewModel().paginationType(1),v=!1},l.ensureActiveTab=function(){!e("#product-grid").hasClass("active")&&!e("#product-list").hasClass("active")&&e("#product-grid").addClass("active")},l.listType()!==i.LIST_VIEW_PRODUCTS&&e.Topic(s.topicNames.SEARCH_RESULTS_UPDATED).subscribe(function(e){l.category(null),v=!0,l.listType()!==i.LIST_VIEW_SEARCH&&(l.listType(i.LIST_VIEW_SEARCH),l.listingViewModel(n.createListingViewModel(l))),l.ensureActiveTab(),this.navigation&&this.navigation.length>0||this.breadcrumbs&&this.breadcrumbs.refinementCrumbs.length>0?l.displayRefineResults(!0):l.displayRefineResults(!1)}),e.Topic(s.topicNames.SEARCH_CREATE).subscribe(function(e){!l.listingViewModel().changedViaDropDown&&!l.changedViaPagination&&!l.productViewed?(l.listingViewModel().itemsPerPage=+l.productsPerPage(),l.listingViewModel().categoryOrSearchChanged=!0,l.changedViaPagination=!1):l.productViewed&&(l.changedViaPagination=!1,l.listingViewModel().categoryOrSearchChanged=!1,l.productViewed=!1)}),e.Topic(s.topicNames.PAGE_VIEW_CHANGED).subscribe(function(e){l.changedViaPagination=!1,e&&e.path=="searchresults"&&e.parameters!=null&&e.parameters.indexOf("&page=")>=0&&(l.changedViaPagination=!0,l.listingViewModel().categoryOrSearchChanged=!1)}),e.Topic(s.topicNames.PRODUCT_VIEWED).subscribe(function(e){l.productViewed=document.location.pathname!="/searchresults"?!0:!1}),w=e(window).width(),e(window).resize(function(){}),l.handlePageChanged=function(t){var n=this;t.pageId!="category"&&t.pageId!="searchresults"&&e(window).off("scroll.page",n.scrollHandler)},e.Topic(s.topicNames.PAGE_CHANGED).subscribe(l.handlePageChanged.bind(l)),l.selectedProductsPerRow(l.getSelectedProductsPerRow()),l.listingViewModel().itemsPerRowInLargeDesktopView(3),l.listingViewModel().itemsPerRowInDesktopView(3),l.listingViewModel().itemsPerRowInTabletView(2),l.listingViewModel().itemsPerRow(1),l.productsPerRowChange(2),l.listingViewModel().currentProducts.subscribe(function(n){var r=n;r&&r.length>0&&(r.forEach(function(e,n){l.loadAllPrices(n,e,"allPrices"),e.compairCheckBox=t.observable(!1);if(p.productsSelectedForComparison()!=undefined&&p.productsSelectedForComparison()!=""&&p.productsSelectedForComparison().length>0)for(var r=0;r '}),t.components.isRegistered("toggle-view-buttons")||t.components.register("toggle-view-buttons",{viewModel:function(e){},template:"
view_week
format_list_bulleted
"})},setGridMode:function(e){e&&(p.isMobile()?p.gridMode(p.gridMode()==="grid"?"list":"grid"):p.gridMode(e))},beforeAppear:function(t){var n=this;n.isMobile(window.innerWidth<992),window.onresize=function(){var e=n.isMobile(),t=window.innerWidth<992;e!=t&&n.isMobile(t)},n.setAdvertisingCard(n),y=n.listType(),n.listingViewModel().resetSortOptions_OCS(),n.listType()==i.LIST_VIEW_SEARCH&&(n.displayRefineResults(!1),n.listingViewModel().titleText(""),n.listingViewModel().noSearchResultsText(""),n.listingViewModel().suggestedSearches({})),n.category()&&n.listType()!=i.LIST_VIEW_SEARCH&&n.categoryUpdate(n.category()),n.listType()===i.LIST_VIEW_PRODUCTS&&(!n.displayRefineResults()||!n.listingViewModel().paginationOnly)&&(n.dimensionId()?n.updateRefinements():(n.displayRefineResults(!1),e.Topic(s.topicNames.OVERLAYED_GUIDEDNAVIGATION_CLEAR).publish())),n.showListViewOption&&n.showListViewButton(n.showListViewOption());if(n.showResultsPerPageOption){var r=n.isScrollEnabled&&n.isScrollEnabled();n.showResultsPerPageSection(n.showResultsPerPageOption()&&!r)}n.listingViewModel().handleResponsiveViewports(),n.productsPerRowChange(3),n.selectedProductsPerRow(3),n.productsSelectedForComparison(f.getValue(f.COMPARATOR.CART_PRODUCTS));var o=a.getInstance();o.enableSpinnerOnPageLoad=!0,setTimeout(function(){e(document).ready(function(){e(".formatkm").each(function(t,n){e(this).text(e(this).text().toString().replace(/\B(?=(\d{3})+(?!\d))/g,"."))}),e(".text_x_version").each(function(t,n){e(this).text(e(this).text().replace("5P",""))})})},1200)},initTooltip:function(){e('[data-toggle="tooltip"]').tooltip()},getPageUrlData:function(e){var t=this;b=e;if(e.pageId==i.CATEGORY_CONTEXT||e.pageId==i.SEARCH_RESULTS)t.listingViewModel().pageId(e.pageId),t.listingViewModel().contextId(e.contextId),t.listingViewModel().seoslug(e.seoslug)},changePage:function(e){var t=this;window.scrollTo(0,0),e.page?t.listingViewModel().pageNumber=parseInt(e.page):(t.listingViewModel().pageNumber=1,t.listingViewModel().initializeIndex()),t.listType()==i.LIST_VIEW_PRODUCTS&&t.scrollHandleOnViewPort(),t.listType()==i.LIST_VIEW_PRODUCTS&&e.paginationOnly&&t.listingViewModel().getPage(t.listingViewModel().pageNumber),t.listingViewModel().paginationOnly=e.paginationOnly,t.listingViewModel().isLoadOnScroll()||(t.productGrid([]),t.listProducts([]))},handleSortingHelper:function(e,t){var n=this;n.productGrid([]),n.listProducts([]),n.listingViewModel().handleSorting(e,t)},handleRefineResults:function(t,n){return!e("#CC-overlayedGuidedNavigation-column").hasClass("open")&&!e("#CC-overlayedGuidedNavigation").hasClass("CC-overlayedGuidedNavigation-mobileView")&&(e("#CC-overlayedGuidedNavigation").addClass("CC-overlayedGuidedNavigation-mobileView"),e.Topic(s.topicNames.OVERLAYED_GUIDEDNAVIGATION_SHOW).publish()),(e(window)[0].innerWidth||e(window).width())=1?n.showBtnReserve(!0):n.showBtnReserve(!1)},function(e){console.log(e)})},stockCyber:function(e){var e=e,n={ids:e.id()};e.showOverlay=t.observable(!1),c.request("listInventories",n,function(t){t[0].stockLevel===888?e.showOverlay(!0):e.showOverlay(!1)},function(e){console.log(e)})},showHighlyViewed:function(e){return f.showHighlyViewed(e.creationDate(),e.x_views())},clickReservarButton:function(e,t){var e=e;l.goTo(e.$data.route())},loadAllPrices:function(e,t,n){f.getAllPrices(t,n)},handleResultsPerPageHelper:function(e,t){var n=this;n.listingViewModel().itemsPerPage!=e.value&&(n.productGrid([]),n.listProducts([]),n.listingViewModel().handleResultsPerPage(e,t))},getProductsPerRowHasFocus:function(e){var t=this,n=t.getSelectedProductsPerRow();return n==e},resultsPerPageCallback:function(e){},selectCarVersion:function(t){e.Topic("addRemoveCartComparator").publish(t)},removeFromView:function(t){var n=this.listingViewModel().currentProducts();if(!n)return;for(var r=0;r=1){var t=e.advertisingCardConfig().split(";"),n=Math.floor(Math.random()*t.length);e.advertisingCard({isActive:!0,position:Math.floor(Math.random()*8)+3,img:t[n].split(",")[0],url:t[n].split(",")[1]})}else e.advertisingCard({isActive:!1})},showAdvertisingCard:function(e){return p.advertisingCard().isActive&&p.advertisingCard().position===e?!0:!1}}})