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

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

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

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

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

    _createClass(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 React.createElement(
                'div',
                { id: 'product-list-warp', className: 'product-list-warp', style: { width: width } },
                dataList.map(function (item, index) {
                    return React.createElement(
                        'div',
                        { key: index, className: 'product-list-item' },
                        item.map(function (v, i) {
                            return React.createElement(WcnSkuItemMagic, { 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;
}(React.Component);

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