'use strict';

Object.defineProperty(exports, "__esModule", {
    value: true
});

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

require('./index.less');

var _index = require('../rotation/index');

var _index2 = _interopRequireDefault(_index);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

var MultipleBanners = function (_React$Component) {
    (0, _inherits3['default'])(MultipleBanners, _React$Component);

    function MultipleBanners() {
        (0, _classCallCheck3['default'])(this, MultipleBanners);

        var _this = (0, _possibleConstructorReturn3['default'])(this, (MultipleBanners.__proto__ || Object.getPrototypeOf(MultipleBanners)).apply(this, arguments));

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

    (0, _createClass3['default'])(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 _react2['default'].createElement(
                'div',
                { id: 'multiple-banners-warp', className: 'multiple-banners-warp', style: { width: width } },
                _react2['default'].createElement(
                    _index2['default'],
                    { dots: false, autoplay: true, autoplaySpeed: autoplaySpeed || 3000 },
                    dataList.map(function (item, index) {
                        return _react2['default'].createElement(
                            'div',
                            { key: index, className: 'multiple-banners-item' },
                            item.map(function (v, i) {
                                return _react2['default'].createElement(
                                    'div',
                                    { onClick: function onClick() {
                                            return clickItem && clickItem(v);
                                        }, key: i, className: 'multiple-banners-single', style: { width: itemWidth, height: itemWidth, marginLeft: itemMargin } },
                                    _react2['default'].createElement('img', { width: '80%', height: '80%', src: v.imgUrl })
                                );
                            })
                        );
                    })
                )
            );
        }
    }]);
    return MultipleBanners;
}(_react2['default'].Component);

MultipleBanners.defaultProps = {
    width: '100%',
    showNum: 5
};
exports['default'] = MultipleBanners;
module.exports = exports['default'];