define(['jquery','Magento_Theme/js/model/breadcrumb-list','underscore','mage/template','text!Magento_Theme/templates/breadcrumbs.html','jquery-ui-modules/widget'],function($,breadcrumbList,_,mageTemplate,tpl){'use strict';return function(widget){$.widget('mage.breadcrumbs',widget,{_render:function(){this._super();var widgetOptions=this.options,self=this;if(undefined!==widgetOptions.seo_breadcrumbs){var configSeo=widgetOptions.seo_breadcrumbs.config,list=widgetOptions.seo_breadcrumbs.list;if(self._checkBreadcrumbsOrNot(configSeo,list)){var pathNamesDefault=self._getPathNamesDefault();var finalPath=[],removeItems=[];_.each(list,function(item){var pathItemArr=item.path.split('/'),pathNamesSeo='',priority=0;pathNamesSeo=self._getPathNames(pathItemArr,list);if(pathNamesSeo===pathNamesDefault){removeItems=self._getRemoveItemIds(item,pathItemArr);}});var removeItemNames=self._getRemoveItemNames(removeItems,list);self._prepareBreadcrumbs(removeItemNames);var html,crumbs=breadcrumbList,template=mageTemplate(tpl);this._decorate(crumbs);html=template({'breadcrumbs':crumbs});if(html.length){$(this.element).html(html);}}}},_checkDrirectlyVisitProduct:function(){if(breadcrumbList.length===2){if(undefined!==breadcrumbList[0]&&breadcrumbList[0].name==='home'&&breadcrumbList[0].first===true&&undefined!==breadcrumbList[1]&&breadcrumbList[1].name==='product'&&breadcrumbList[1].last===true){return true;}} return false;},_checkBreadcrumbsOrNot:function(configSeo,list){return configSeo.enabled==="1"&&configSeo.breadcrumbs_type==='short'&&configSeo.used_priority==="1"&&!this._checkDrirectlyVisitProduct()&&undefined!==list;},_getPathNamesDefault:function(){var pathNamesDefault='';_.each(breadcrumbList,function(breadcrumb){if(breadcrumb.name==="category"){pathNamesDefault=pathNamesDefault+breadcrumb.label+'+';}});return pathNamesDefault;},_getPathNames:function(pathIds,list){var pathNames='';_.each(pathIds,function(pathId){_.each(list,function(item){if(item.entity_id===pathId&&item.entity_id!=="1"&&item.entity_id!=="2"){pathNames=pathNames+item.name+'+';}});});return pathNames;},_getRemoveItemIds:function(item,pathItemArr){var priority=item.priority_id,i=0,removeItems=[];if(priority!==null&&!isNaN(parseInt(priority))){for(;i