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';
import React from 'react';
import { Rate, Icon } from '@whalecloud/fdx';
import SkuImgSlider from '../sku-img-slider';
import CommodityInfo from './commodity-info';
import './index.less';
var CLICK_TYPE;
(function (CLICK_TYPE) {
    CLICK_TYPE["IMG"] = "IMG";
    CLICK_TYPE["TITLE"] = "TITLE";
    CLICK_TYPE["COLLECTION"] = "COLLECTION";
    CLICK_TYPE["RATE"] = "RATE";
    CLICK_TYPE["STORE"] = "STORE";
    CLICK_TYPE["REVIEW"] = "REVIEW";
})(CLICK_TYPE || (CLICK_TYPE = {}));

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

    function CommodityCard(props) {
        _classCallCheck(this, CommodityCard);

        var _this = _possibleConstructorReturn(this, (CommodityCard.__proto__ || Object.getPrototypeOf(CommodityCard)).call(this, props));

        _this.state = {
            sku: ""
        };
        return _this;
    }

    _createClass(CommodityCard, [{
        key: 'render',
        value: function render() {
            var _this2 = this;

            var _props = this.props,
                data = _props.data,
                _onClick = _props.onClick,
                rowKey = _props.rowKey,
                _props$needMagnifier = _props.needMagnifier,
                needMagnifier = _props$needMagnifier === undefined ? false : _props$needMagnifier,
                multiple = _props.multiple,
                smallImgField = _props.smallImgField,
                middleImgField = _props.middleImgField,
                largeImgField = _props.largeImgField,
                videoField = _props.videoField,
                _props$width = _props.width,
                width = _props$width === undefined ? 194 : _props$width,
                slideNum = _props.slideNum,
                nodePadding = _props.nodePadding,
                _props$sliderMarginTo = _props.sliderMarginTop,
                sliderMarginTop = _props$sliderMarginTo === undefined ? 8 : _props$sliderMarginTo,
                needBorder = _props.needBorder;
            var sku = this.state.sku;

            return React.createElement(
                'div',
                { className: 'commodity-card-wrap' },
                React.createElement(
                    'div',
                    { className: data.isCollection ? "select" : "deSelect" },
                    React.createElement(Rate, { className: 'collection-heart', character: React.createElement(Icon, { type: 'heart', theme: 'filled' }), count: 1, value: data.isCollection ? 1 : 0, onChange: function onChange(v) {
                            return _onClick && _onClick(CLICK_TYPE.COLLECTION, _extends(_extends({}, data), { isCollection: v }));
                        } })
                ),
                React.createElement(SkuImgSlider, { dataSource: data.imgList, needMagnifier: needMagnifier, width: width, sliderMarginTop: sliderMarginTop, slideNum: slideNum, rowKey: rowKey, multiple: multiple, smallImgField: smallImgField, middleImgField: middleImgField, largeImgField: largeImgField, videoField: videoField, nodePadding: nodePadding, needBorder: needBorder, onClick: function onClick() {
                        return _onClick && _onClick(CLICK_TYPE.IMG, data);
                    }, onChangeSku: function onChangeSku(data) {
                        return _this2.setState({ sku: data });
                    } }),
                React.createElement(CommodityInfo, { data: data.info, sku: sku === "" ? data.imgList[0] : sku, onRateClick: function onRateClick() {
                        return _onClick && _onClick(CLICK_TYPE.RATE, data);
                    }, onTitleClick: function onTitleClick() {
                        return _onClick && _onClick(CLICK_TYPE.TITLE, data);
                    }, onReviewClick: function onReviewClick() {
                        return _onClick && _onClick(CLICK_TYPE.REVIEW, data);
                    }, onStoreClick: function onStoreClick() {
                        return _onClick && _onClick(CLICK_TYPE.STORE, data);
                    } })
            );
        }
    }]);

    return CommodityCard;
}(React.Component);

export default CommodityCard;