'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('../wcn-sku-item-magic/index');

var _index2 = _interopRequireDefault(_index);

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

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

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

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

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

    (0, _createClass3['default'])(ProductList, [{
        key: 'componentDidMount',
        value: function componentDidMount() {
            this.setState({
                width: document.getElementById('product-list-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;

            var itemWidth = (clientWidth - 16 * (showNum - 1)) / showNum;
            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: 'product-list-warp', className: 'product-list-warp', style: { width: width } },
                dataList.map(function (item, index) {
                    return _react2['default'].createElement(
                        'div',
                        { key: index, className: 'product-list-item' },
                        item.map(function (v, i) {
                            return _react2['default'].createElement(_index2['default'], { clickItem: clickItem, imgStyle: { width: itemWidth, height: itemWidth, padding: '16px', boxSizing: 'border-box' }, style: { width: itemWidth, marginRight: (i + 1) % 5 === 0 ? 0 : 16 }, data: v, key: i })
                            // <div onClick={() => clickItem && clickItem(v)} key={i} className="product-list-single" style={{width: itemWidth, marginLeft: itemMargin}}>
                            //     <img width='94%' src={v.productImageUrl}/>
                            //     <div className="product-list-single-name">{v.productName}</div>
                            //     <div className="product-list-single-price">$ {v.salesPrice}</div>
                            // </div>
                            ;
                        })
                    );
                })
            );
        }
    }]);
    return ProductList;
}(_react2['default'].Component);

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