define(["knockout","CCi18n","ccResourceLoader!global/OCS_BFService"],function(e,t,n){"use strict";var r={AU:"automovil-usado",AN:"Automovil",CATEGORY_AU:"autos-usados"},i;return{allCollections:e.observable(),breadcrumb:e.observableArray([]),onLoad:function(e){i=e,$.Topic("ALL_COLLECTIONS.memory").subscribe(function(t){e.allCollections(t)})},beforeAppear:function(e){var t=this;t.allCollections()?t.buildBreadCrumb():t.allCollections.subscribe(function(){t.buildBreadCrumb()})},buildBreadCrumb:function(){var e=this,t=[],i=e.product().type()==r.AN?e.getCategory:n.utils.catalog.findCollection;e.product().parentCategories().filter(function(e){return e.active()}).forEach(function(n){t.push(i(n.id(),e.allCollections().childCategories))}),t=t.filter(function(e){return e}),n.utils.sortJsonByField(t,"x_breadcrumbPriority"),e.product().type()==r.AU&&e.runCustomLogicAU(t),e.renderBreadcrumb(t.map(function(e){return{label:e.displayName,url:e.route}}))},runCustomLogicAU:function(e){var t=e.find(function(e){return e.id==r.CATEGORY_AU});if(!t){var i=n.utils.catalog.findCollection(r.CATEGORY_AU);e.unshift(i)}},renderBreadcrumb:function(e){var t=this,n=t.levels&&t.levels()?t.levels():2;e=e.slice(0,n),t.addProductCrumb(e),t.breadcrumb(e)},getCategory:function(e,t){var n="",r;return t&&$.each(t,function(t,s){if(s.id==e&&s.id.toUpperCase().indexOf("TODOS")==-1)return n=s,!1;if(s.childCategories!==undefined&&s.id.toUpperCase().indexOf("TODOS")==-1){r=i.getCategory(e,s.childCategories);if(r)return n=r,!1}}),n},addProductCrumb:function(e){var t="";if(i.product().type()===r.AU)t=i.product().x_marca()+" "+i.product().x_modelo()+" "+i.product().x_version();else{var s=n.utils.product.getModelVersion(i.product());t=i.product().brand()+" "+s.model+" "+i.product().displayName()}e.push({label:t})}}})