import React from "react";
import { connect } from "react-redux";

class Company extends React.Component 
{
	constructor(props)
	{
		super(props);
		this.state = {
			company: {}, 
		}
	}

	static getDerivedStateFromProps(nextProps, prevState) 
	{
		return {
			company: nextProps.company,
		};
	}

	render()
	{
		const { company } = this.state;
		return (
			<div className="right company-dropdown">
				<p align="right" className="arrow">
				<b>{ company.title }</b><br/>
				{company.inn != null && <span>ИНН: { company.inn } </span>}
				{company.kpp != null && <span>КПП: { company.kpp }</span>}
				</p>

				<div className="companies_list"> {/* opened */}
					<div className="company_item">
						<p align="right">
							<b>ООО “ЮКС“</b><br/>
							ИНН: <span>12345678765</span> КПП: <span>13432-02</span>
						</p>
					</div>

					<div className="company_item">
						<p align="right">
							<b>ООО “Еще одно название”</b><br/>
							ИНН: <span>12345678765</span> КПП: <span>13432-02</span>
						</p>
					</div>

					<div className="company_item selected">
						<p align="right">
							<b>ООО “Друзья и КО”</b><br/>
							ИНН: <span>12345678765</span> КПП: <span>13432-02</span>
						</p>
					</div>
				</div>
			</div>
		)
	}
}

function mapStateToProps(state, ownProps)
{
	return {
		company: state.company, 
	}
}

export default connect(mapStateToProps)(Company);