import _toConsumableArray from"babel-runtime/helpers/toConsumableArray";import _defineProperty from"babel-runtime/helpers/defineProperty";import _extends from"babel-runtime/helpers/extends";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";var __rest=this&&this.__rest||function(e,t){var r={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&t.indexOf(a)<0&&(r[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(a=Object.getOwnPropertySymbols(e);o<a.length;o++)t.indexOf(a[o])<0&&(r[a[o]]=e[a[o]])}return r};import*as React from"react";import*as PropTypes from"prop-types";import classNames from"classnames";import LocaleReceiver from"../locale-provider/LocaleReceiver";import defaultLocale from"../locale-provider/default";import Spin from"../spin";import Pagination from"../pagination";import{Row}from"../grid";import Item from"./Item";var List=function(e){function t(){_classCallCheck(this,t);var e=_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments));return e.state={paginationCurrent:1},e.defaultPaginationProps={current:1,pageSize:10,onChange:function(t,r){var a=e.props.pagination;e.setState({paginationCurrent:t}),a&&a.onChange&&a.onChange(t,r)},total:0},e.keys={},e.renderItem=function(t,r){var a=e.props,o=a.dataSource,n=a.renderItem,i=a.rowKey,s=void 0;return(s="function"==typeof i?i(o[r]):"string"==typeof i?o[i]:o.key)||(s="list-item-"+r),e.keys[r]=s,n(t,r)},e.renderEmpty=function(t){var r=_extends({},t,e.props.locale);return React.createElement("div",{className:e.props.prefixCls+"-empty-text"},r.emptyText)},e}return _inherits(t,e),_createClass(t,[{key:"getChildContext",value:function(){return{grid:this.props.grid}}},{key:"isSomethingAfterLastItem",value:function(){var e=this.props,t=e.loadMore,r=e.pagination,a=e.footer;return!!(t||r||a)}},{key:"render",value:function(){var e,t=this,r=this.state.paginationCurrent,a=this.props,o=a.bordered,n=a.split,i=a.className,s=a.children,l=a.itemLayout,p=a.loadMore,c=a.pagination,m=a.prefixCls,d=a.grid,u=a.dataSource,f=a.size,g=(a.rowKey,a.renderItem,a.header),h=a.footer,y=a.loading,b=(a.locale,__rest(a,["bordered","split","className","children","itemLayout","loadMore","pagination","prefixCls","grid","dataSource","size","rowKey","renderItem","header","footer","loading","locale"])),v=y;"boolean"==typeof v&&(v={spinning:v});var _=v&&v.spinning,C="";switch(f){case"large":C="lg";break;case"small":C="sm"}var P=classNames(m,i,(_defineProperty(e={},m+"-vertical","vertical"===l),_defineProperty(e,m+"-"+C,C),_defineProperty(e,m+"-split",n),_defineProperty(e,m+"-bordered",o),_defineProperty(e,m+"-loading",_),_defineProperty(e,m+"-grid",d),_defineProperty(e,m+"-something-after-last-item",this.isSomethingAfterLastItem()),e)),R=_extends({},this.defaultPaginationProps,{total:u.length,current:r},c||{}),x=Math.ceil(R.total/R.pageSize);R.current>x&&(R.current=x);var S=c?React.createElement("div",{className:m+"-pagination"},React.createElement(Pagination,_extends({},R,{onChange:this.defaultPaginationProps.onChange}))):null,L=[].concat(_toConsumableArray(u));c&&u.length>(R.current-1)*R.pageSize&&(L=[].concat(_toConsumableArray(u)).splice((R.current-1)*R.pageSize,R.pageSize));var E=void 0;if(E=_&&React.createElement("div",{style:{minHeight:53}}),L.length>0){var k=L.map(function(e,r){return t.renderItem(e,r)}),I=React.Children.map(k,function(e,r){return React.cloneElement(e,{key:t.keys[r]})});E=d?React.createElement(Row,{gutter:d.gutter},I):I}else s||_||(E=React.createElement(LocaleReceiver,{componentName:"Table",defaultLocale:defaultLocale.Table},this.renderEmpty));var N=R.position||"bottom";return React.createElement("div",_extends({className:P},b),("top"===N||"both"===N)&&S,g&&React.createElement("div",{className:m+"-header"},g),React.createElement(Spin,v,E,s),h&&React.createElement("div",{className:m+"-footer"},h),p||("bottom"===N||"both"===N)&&S)}}]),t}(React.Component);export default List;List.Item=Item,List.childContextTypes={grid:PropTypes.any},List.defaultProps={dataSource:[],prefixCls:"dt-list",bordered:!1,split:!0,loading:!1,pagination:!1};