import * as React from 'react';
import PropsTypes from './types';

interface State extends PropsTypes {
    show: boolean
}

export default class InputDropdown extends React.Component<PropsTypes, State> {

    constructor(props: PropsTypes, public state: State) {
        super(props);

        this.state = {
            show: this.props.show || false
        }
    }

    componentWillReceiveProps(props) {
        if (props.show !== this.props.show) {
            this.setState({
                show: !this.state.show
            })
        }
    }

    showHide() {
        this.setState({
            show: !this.state.show
        })
    }

    render() {
        const {children, show, size} = this.props;
        if (show) {
            return <div className={`krax-dropdown-menu result-box ${size}`} role="menu">
                <div className="krax-dropdown-content">
                    {children}
                </div>
            </div>
        }

        return null
    }
}
