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 React from 'react';
import './index.less';
import Rotation from '../rotation/index';

var MultipleBanners = function (_React$Component) {
    _inherits(MultipleBanners, _React$Component);

    function MultipleBanners() {
        _classCallCheck(this, MultipleBanners);

        var _this = _possibleConstructorReturn(this, (MultipleBanners.__proto__ || Object.getPrototypeOf(MultipleBanners)).apply(this, arguments));

        _this.state = {
            width: 0
        };
        return _this;
    }

    _createClass(MultipleBanners, [{
        key: 'componentDidMount',
        value: function componentDidMount() {
            this.setState({
                width: document.getElementById('multiple-banners-warp').clientWidth
            });
        }
    }, {
        key: 'render',
        value: function render() {
            var clientWidth = this.state.width;
            var _props = this.props,
                width = _props.width,
                showNum = _props.showNum,
                data = _props.data,
                clickItem = _props.clickItem,
                autoplaySpeed = _props.autoplaySpeed;

            var itemWidth = clientWidth / (showNum + 1);
            var itemMargin = itemWidth / (showNum + 1);
            var dataList = [];
            var splitNum = Math.ceil(data.length / showNum);
            for (var i = 0; i < splitNum; i++) {
                dataList[i] = [];
                for (var j = 0; j < showNum; j++) {
                    if (i * showNum + j >= data.length) {
                        break;
                    }
                    dataList[i].push(data[i * showNum + j]);
                }
            }
            return React.createElement(
                'div',
                { id: 'multiple-banners-warp', className: 'multiple-banners-warp', style: { width: width } },
                React.createElement(
                    Rotation,
                    { dots: false, autoplay: true, autoplaySpeed: autoplaySpeed || 3000 },
                    dataList.map(function (item, index) {
                        return React.createElement(
                            'div',
                            { key: index, className: 'multiple-banners-item' },
                            item.map(function (v, i) {
                                return React.createElement(
                                    'div',
                                    { onClick: function onClick() {
                                            return clickItem && clickItem(v);
                                        }, key: i, className: 'multiple-banners-single', style: { width: itemWidth, height: itemWidth, marginLeft: itemMargin } },
                                    React.createElement('img', { width: '80%', height: '80%', src: v.imgUrl })
                                );
                            })
                        );
                    })
                )
            );
        }
    }]);

    return MultipleBanners;
}(React.Component);

MultipleBanners.defaultProps = {
    width: '100%',
    showNum: 5
};
export default MultipleBanners;