import {
    inject,
    observer
} from 'mobx-react'
import {
    WeaTab
} from 'ecCom'

@inject('hrmApplicant') //todo
@observer
export default class Tab extends React.Component {
    constructor(props) {
        super(props);
    }

    componentDidMount() {
        const {
            hrmApplicant
        } = this.props, {
            mainDialog
        } = hrmApplicant, {
            type
        } = mainDialog;

        type != 'more' && this.props.hrmApplicant.getSearchCondition();
    }

    componentWillUnmount() {
        this.props.hrmApplicant.resetTab();
    }

    render() {
        const {
            hrmApplicant
        } = this.props, {
            tab,
            buttonsAd,
            changePanelStatus,
            searchsAd,
            handleSearch,
            mainDialog,
            setSearchBaseValue,
        } = hrmApplicant, {
            isPanelShow,
            conditionCount,
            form,
            searchBaseValue,
        } = tab, {
            type
        } = mainDialog;

        return (
            <WeaTab ecId={`${this && this.props && this.props.ecId || ''}_WeaTab@i0escg`}
                searchType={type=='more' ? ['base'] : ['base','advanced']}
                showSearchAd={isPanelShow}
                hasMask={false}
                advanceHeight={Math.ceil(conditionCount / 2)*52+20}
                buttonsAd={buttonsAd}
                searchsBaseValue={type=='more' ? searchBaseValue : form.getFormParams().name}
                setShowSearchAd={  b => changePanelStatus(b)}
                hideSearchAd={ () => changePanelStatus(false)}
                searchsAd= {searchsAd}
                onSearch={() => handleSearch()}
                onSearchChange={val => {type=='more' ? setSearchBaseValue(val) : form.updateFields({name: val})}}
            />
        )

    }
}