import React, {Component} from 'react';
import {connect} from 'react-redux';
import {Row, Col, Input} from 'reactstrap';
import {fetchShopPackages} from '../../actions/coMarket/coMarketPackagesActions';
import {coMarketTexts} from '../../constants/coMarketConstants';

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

        this.handleSearchChange = this.handleSearchChange.bind(this);
        this.state = {
            searchValue : ''
        };
    }

    handleSearchChange(event) {
        this.setState({searchValue: event.target.value});
        this.props.dispatch(fetchShopPackages(this.props.selectedCommercialLead, event.target.value));
    }

    render() {
        return (
            <Row className="co-market-nav">
                <Col xl="4" lg="3" md="3" sm="12" xs="12" className="co-market-nav-buttons">
                    <div className="co-market-nav-div">
                        {coMarketTexts.labels.NEW_PRODUCTS}
                    </div>
                </Col>
                <Col xl="4" lg="4" md="4" xs="12" className="search-layer">
                    <div className="co-market-nav-div">
                        <i className="search-package-icon fa fa-search" aria-hidden="true"></i>
                        <Input className="wiaas-input" onChange={this.handleSearchChange} value={this.state.searchValue} placeholder={coMarketTexts.labels.SEARCH_PACKAGE}/>
                    </div>
                </Col>
            </Row>
        );
    }
}

const mapStateToProps = (state) => ({
    selectedCommercialLead: state.coMarketPackagesReducer.selectedCommercialLead
});

export default connect(mapStateToProps)(CoMarketNavContainer);
