'use strict';

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

var _extends2 = require('babel-runtime/helpers/extends');

var _extends3 = _interopRequireDefault(_extends2);

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);

var _fdx = require('@whalecloud/fdx');

var _skuImgSlider = require('../sku-img-slider');

var _skuImgSlider2 = _interopRequireDefault(_skuImgSlider);

var _commodityInfo = require('./commodity-info');

var _commodityInfo2 = _interopRequireDefault(_commodityInfo);

require('./index.less');

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

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) {
    (0, _inherits3['default'])(CommodityCard, _React$Component);

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

        var _this = (0, _possibleConstructorReturn3['default'])(this, (CommodityCard.__proto__ || Object.getPrototypeOf(CommodityCard)).call(this, props));

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

    (0, _createClass3['default'])(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 _react2['default'].createElement(
                'div',
                { className: 'commodity-card-wrap' },
                _react2['default'].createElement(
                    'div',
                    { className: data.isCollection ? "select" : "deSelect" },
                    _react2['default'].createElement(_fdx.Rate, { className: 'collection-heart', character: _react2['default'].createElement(_fdx.Icon, { type: 'heart', theme: 'filled' }), count: 1, value: data.isCollection ? 1 : 0, onChange: function onChange(v) {
                            return _onClick && _onClick(CLICK_TYPE.COLLECTION, (0, _extends3['default'])((0, _extends3['default'])({}, data), { isCollection: v }));
                        } })
                ),
                _react2['default'].createElement(_skuImgSlider2['default'], { 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 });
                    } }),
                _react2['default'].createElement(_commodityInfo2['default'], { 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;
}(_react2['default'].Component);

exports['default'] = CommodityCard;
module.exports = exports['default'];