import _classCallCheck from"babel-runtime/helpers/classCallCheck";import _createClass from"babel-runtime/helpers/createClass";import _possibleConstructorReturn from"babel-runtime/helpers/possibleConstructorReturn";import _inherits from"babel-runtime/helpers/inherits";import*as React from"react";import*as PropTypes from"prop-types";import{cloneElement}from"react";import warning from"../_util/warning";import BreadcrumbItem from"./BreadcrumbItem";import classNames from"classnames";function getBreadcrumbName(e,r){if(!e.breadcrumbName)return null;var t=Object.keys(r).join("|");return e.breadcrumbName.replace(new RegExp(":("+t+")","g"),function(e,t){return r[t]||e})}function defaultItemRender(e,r,t,a){var n=t.indexOf(e)===t.length-1,s=getBreadcrumbName(e,r);return n?React.createElement("span",null,s):React.createElement("a",{href:"#/"+a.join("/")},s)}var Breadcrumb=function(e){function r(){return _classCallCheck(this,r),_possibleConstructorReturn(this,(r.__proto__||Object.getPrototypeOf(r)).apply(this,arguments))}return _inherits(r,e),_createClass(r,[{key:"componentDidMount",value:function(){var e=this.props;warning(!("linkRender"in e||"nameRender"in e),"`linkRender` and `nameRender` are removed, please use `itemRender` instead, see: #.")}},{key:"render",value:function(){var e=void 0,r=this.props,t=r.separator,a=r.prefixCls,n=r.style,s=r.className,o=r.routes,p=r.params,m=void 0===p?{}:p,c=r.children,i=r.itemRender,l=void 0===i?defaultItemRender:i;if(o&&o.length>0){var u=[];e=o.map(function(e){e.path=e.path||"";var r=e.path.replace(/^\//,"");return Object.keys(m).forEach(function(e){r=r.replace(":"+e,m[e])}),r&&u.push(r),React.createElement(BreadcrumbItem,{separator:t,key:e.breadcrumbName||r},l(e,m,o,u))})}else c&&(e=React.Children.map(c,function(e,r){return e?(warning(e.type&&e.type.__ANT_BREADCRUMB_ITEM,"Breadcrumb only accepts Breadcrumb.Item as it's children"),cloneElement(e,{separator:t,key:r})):e}));return React.createElement("div",{className:classNames(s,a),style:n},e)}}]),r}(React.Component);export default Breadcrumb;Breadcrumb.defaultProps={prefixCls:"dt-breadcrumb",separator:"/"},Breadcrumb.propTypes={prefixCls:PropTypes.string,separator:PropTypes.node,routes:PropTypes.array,params:PropTypes.object,linkRender:PropTypes.func,nameRender:PropTypes.func};