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

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

var _ecomIcon = require('../ecom-icon');

var _ecomIcon2 = _interopRequireDefault(_ecomIcon);

require('./index.less');

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

var Seven = _ecomIcon2['default'].Seven,
    QualityProduct = _ecomIcon2['default'].QualityProduct;

var CLICK_TYPE;
(function (CLICK_TYPE) {
    CLICK_TYPE["CHECKBOX"] = "CHECKBOX";
    CLICK_TYPE["ORDERID"] = "ORDERID";
    CLICK_TYPE["STORE"] = "STORE";
    CLICK_TYPE["IMG"] = "IMG";
    CLICK_TYPE["TITLE"] = "TITLE";
    CLICK_TYPE["DETAIL"] = "DETAIL";
    CLICK_TYPE["UNPAID"] = "UNPAID";
    CLICK_TYPE["CONFIRM"] = "CONFIRM";
    CLICK_TYPE["RATING"] = "RATING";
    CLICK_TYPE["RETURN"] = "RETURN";
    CLICK_TYPE["AGAIN"] = "AGAIN";
    CLICK_TYPE["CANCEL"] = "CANCEL";
})(CLICK_TYPE || (CLICK_TYPE = {}));
var STATE_TO_NAME;
(function (STATE_TO_NAME) {
    STATE_TO_NAME["A"] = "Unpaid";
    STATE_TO_NAME["B"] = "To Ship";
    STATE_TO_NAME["C"] = "To Receive";
    STATE_TO_NAME["D"] = "Completed";
    STATE_TO_NAME["E"] = "Cancelled";
})(STATE_TO_NAME || (STATE_TO_NAME = {}));
var NAME_TO_STATE;
(function (NAME_TO_STATE) {
    NAME_TO_STATE["UNPAID"] = "A";
    NAME_TO_STATE["TO_SHIP"] = "B";
    NAME_TO_STATE["TO_RECEIVED"] = "C";
    NAME_TO_STATE["COMPLETED"] = "D";
    NAME_TO_STATE["CANCELLED"] = "E";
})(NAME_TO_STATE || (NAME_TO_STATE = {}));
var SHIP_STATE;
(function (SHIP_STATE) {
    SHIP_STATE["ALL_SHIP"] = "C";
})(SHIP_STATE || (SHIP_STATE = {}));

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

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

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

        _this.getBtnGroup = function (data) {
            var _onClick = _this.props.onClick;

            var unpaidBtnGrp = _react2['default'].createElement(
                _react.Fragment,
                null,
                _react2['default'].createElement(
                    _fdx.Button,
                    { className: 'pay-btn', ghost: true, onClick: function onClick() {
                            return _onClick && _onClick(CLICK_TYPE.UNPAID, data);
                        } },
                    _react2['default'].createElement(
                        'span',
                        null,
                        'Pay now'
                    )
                ),
                _react2['default'].createElement(
                    'a',
                    { className: 'cancel-a', onClick: function onClick() {
                            return _onClick && _onClick(CLICK_TYPE.CANCEL, data);
                        } },
                    'Cancel'
                )
            );
            var toReceiveBtnGrp = _react2['default'].createElement(
                _react.Fragment,
                null,
                _react2['default'].createElement(
                    _fdx.Button,
                    { className: 'receipt-btn', type: 'primary', ghost: true, onClick: function onClick() {
                            return _onClick && _onClick(CLICK_TYPE.CONFIRM, data);
                        } },
                    _react2['default'].createElement(
                        'span',
                        null,
                        'Confirm Receipt'
                    )
                ),
                _react2['default'].createElement(
                    'a',
                    { className: 'detail-a', onClick: function onClick() {
                            return _onClick && _onClick(CLICK_TYPE.AGAIN, data);
                        } },
                    'Buy again'
                )
            );
            var completBtnGrp = _react2['default'].createElement(
                _react.Fragment,
                null,
                data.canEvaluate === 'Y' ? _react2['default'].createElement(
                    _fdx.Button,
                    { className: 'review-btn', type: 'default', ghost: true, onClick: function onClick() {
                            return _onClick && _onClick(CLICK_TYPE.RATING, data);
                        } },
                    _react2['default'].createElement(
                        'span',
                        null,
                        'Rating'
                    )
                ) : null,
                _react2['default'].createElement(
                    'a',
                    { className: 'detail-a', onClick: function onClick() {
                            return _onClick && _onClick(CLICK_TYPE.AGAIN, data);
                        } },
                    'Buy again'
                )
            );
            var cancelBtnGrp = _react2['default'].createElement(
                'a',
                { className: 'detail-a', onClick: function onClick() {
                        return _onClick && _onClick(CLICK_TYPE.AGAIN, data);
                    } },
                'Buy again'
            );
            return _react2['default'].createElement(
                'td',
                { rowSpan: data.orderItems.length, className: 'tr-td td-operation' },
                data.status === NAME_TO_STATE.UNPAID && unpaidBtnGrp,
                data.deliveryState === SHIP_STATE.ALL_SHIP && data.status === NAME_TO_STATE.TO_RECEIVED && toReceiveBtnGrp,
                data.status === NAME_TO_STATE.COMPLETED && completBtnGrp,
                data.status === NAME_TO_STATE.CANCELLED && cancelBtnGrp,
                _react2['default'].createElement(
                    'a',
                    { className: 'detail-a', onClick: function onClick() {
                            return _onClick && _onClick(CLICK_TYPE.DETAIL, data);
                        } },
                    'Detail'
                )
            );
        };
        return _this;
    }

    (0, _createClass3['default'])(OrderItem, [{
        key: 'render',
        value: function render() {
            var _this2 = this;

            var _props = this.props,
                data = _props.data,
                _onClick2 = _props.onClick;

            return _react2['default'].createElement(
                'table',
                { className: data.status === 'Completion' ? 'order-item-warp-gray' : 'order-item-warp' },
                _react2['default'].createElement(
                    'tbody',
                    null,
                    _react2['default'].createElement(
                        'tr',
                        { className: data.status === 'Completion' ? 'tr-th-gray' : 'tr-th' },
                        _react2['default'].createElement(
                            'td',
                            { colSpan: 5, className: 'tr-td' },
                            _react2['default'].createElement(
                                'span',
                                { className: 's-dateTime' },
                                _react2['default'].createElement(_fdx.Checkbox, { className: 's-checkbox', onChange: function onChange(v) {
                                        return _onClick2 && _onClick2(CLICK_TYPE.CHECKBOX, v);
                                    } }),
                                data && data.createTime
                            ),
                            _react2['default'].createElement(
                                'span',
                                { className: 's-orderID' },
                                'Order No.:',
                                _react2['default'].createElement(
                                    'span',
                                    { className: 's-order-content', onClick: function onClick() {
                                            return _onClick2 && _onClick2(CLICK_TYPE.ORDERID, data);
                                        } },
                                    data && data.orderNbr
                                )
                            ),
                            _react2['default'].createElement(
                                'span',
                                { className: 's-store' },
                                _react2['default'].createElement(_fdx.Icon, { type: 'shop', className: 's-icon' }),
                                _react2['default'].createElement(
                                    'span',
                                    { onClick: function onClick() {
                                            return _onClick2 && _onClick2(CLICK_TYPE.STORE, data);
                                        } },
                                    data && data.store
                                )
                            )
                        )
                    ),
                    data.orderItems.map(function (d, index) {
                        return _react2['default'].createElement(
                            'tr',
                            { className: 'tr-bd', key: d.id + index },
                            _react2['default'].createElement(
                                'td',
                                { className: 'tr-td td-goods' },
                                _react2['default'].createElement(
                                    'div',
                                    { className: 'goods-item', onClick: function onClick() {
                                            return _onClick2 && _onClick2(CLICK_TYPE.IMG, data, d);
                                        } },
                                    _react2['default'].createElement('img', { src: d && d.img, style: { width: '56px', height: '56px' } })
                                ),
                                _react2['default'].createElement(
                                    'div',
                                    { className: 'goods-msg' },
                                    _react2['default'].createElement(
                                        'div',
                                        { className: 'goods-title', title: '' + (d && d.title), onClick: function onClick() {
                                                return _onClick2 && _onClick2(CLICK_TYPE.TITLE, data, d);
                                            } },
                                        d && d.title
                                    ),
                                    _react2['default'].createElement(
                                        'div',
                                        { className: 'goods-description', title: '' + (d && d.description) },
                                        d && d.description
                                    ),
                                    _react2['default'].createElement(
                                        'div',
                                        { className: 'goods-icon' },
                                        _react2['default'].createElement(Seven, { style: { color: '#14C97E', marginRight: 10 } }),
                                        _react2['default'].createElement(QualityProduct, { style: { color: '#14C97E', marginRight: 10 } })
                                    )
                                ),
                                _react2['default'].createElement(
                                    'div',
                                    { className: 'goods-price' },
                                    d && d.price
                                ),
                                _react2['default'].createElement(
                                    'div',
                                    { className: 'goods-number' },
                                    d && d.number
                                )
                            ),
                            _react2['default'].createElement(
                                'td',
                                { className: 'tr-td td-ship' },
                                data.status === NAME_TO_STATE.COMPLETED ? _react2['default'].createElement(
                                    'span',
                                    { className: 'refund', onClick: function onClick() {
                                            _onClick2 && _onClick2(CLICK_TYPE.RETURN, data, d);
                                        } },
                                    'Refund & Return'
                                ) : null
                            ),
                            index === 0 && _react2['default'].createElement(
                                _react.Fragment,
                                null,
                                _react2['default'].createElement(
                                    'td',
                                    { rowSpan: data.orderItems.length, className: 'tr-td td-status' },
                                    _react2['default'].createElement(
                                        'div',
                                        null,
                                        STATE_TO_NAME[data.status]
                                    )
                                ),
                                _react2['default'].createElement(
                                    'td',
                                    { rowSpan: data.orderItems.length, className: 'tr-td td-amount' },
                                    data && data.totalAmount
                                ),
                                _this2.getBtnGroup(data)
                            )
                        );
                    })
                )
            );
        }
    }]);
    return OrderItem;
}(_react2['default'].Component);

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