import React, {Component} from 'react';
import {connect} from 'react-redux';
import {Button} from 'reactstrap';
import { WiaasTableRow, WiaasTableCol} from '../../../mainComponents/table/WiaasTable.jsx';
import {setBid} from '../../../actions/bids/bidsActions';
import {cartTexts} from '../../../constants/cartConstants';

class BidItem extends Component {
    constructor(props) {
        super(props);

        this.onBidSelect = this.onBidSelect.bind(this);
    }
    onBidSelect(idBid){
        this.props.dispatch(setBid(idBid, this.props.idCart));
    }

    render() {
        const {bid, idSelectedBid} = this.props;
        return (
            <WiaasTableRow className="bid-item">
                <WiaasTableCol header={cartTexts.labels.BID_NUMBER}>{bid.bidNumber}</WiaasTableCol>
                <WiaasTableCol header={cartTexts.labels.START_DATE}>{bid.startDate}</WiaasTableCol>
                <WiaasTableCol header={cartTexts.labels.END_DATE}>{bid.endDate}</WiaasTableCol>
                <WiaasTableCol header={cartTexts.labels.FIXED}>{bid.fixedPrice}</WiaasTableCol>
                <WiaasTableCol header={cartTexts.labels.RECURRENT}>{bid.recurrentPrice}</WiaasTableCol>
                <WiaasTableCol header={cartTexts.labels.SERVICES}>{bid.servicesPrice}</WiaasTableCol>
                <WiaasTableCol header={cartTexts.labels.ACTIONS}>
                    {
                        idSelectedBid === bid.idBid
                        ? <Button onClick={()=>{this.onBidSelect(null)}}><span className="fa fa-times remove-item"></span> {cartTexts.buttons.REMOVE}</Button>
                        : <Button onClick={()=>{this.onBidSelect(bid.idBid)}}>{cartTexts.buttons.USE}</Button>
                    }
                </WiaasTableCol>
            </WiaasTableRow>
        );
    }
}

export default connect()(BidItem);
