import {
	observer
} from 'mobx-react';
import {
	WeaLocaleProvider,
} from 'ecCom';
import Menus from './Menus';
import NoLinkageForm from './NoLinkageForm';
import CollapseForm from './CollapseForm';
import Table from './Table';
import Tab from './Tab';
import Step from './Step';
import Title from './Title';
import TableUnderSearchGroup from './TableUnderSearchGroup';
const getLabel = WeaLocaleProvider.getLabel;

@observer
export default class PageContent extends React.Component {
	constructor(props) {
		super(props);
	}

	getInfo = (index) => {
		if (index === 0) {
			return this.getStepOneInfo()
		} else if (index === 1) {
			return this.getStepTwoInfo()
		} else {
			return this.getStepThreeInfo()
		}
	}

	getStepOneInfo = () => {
		const {
			store
		} = this.props, {
			personalForm,
			conditionForm,
			cPage,
			modify
		} = store;

		const personInfo = (
			<div>
				<Title title={getLabel(-1,'本人信息')} clickEventListener={modify}/>
				<NoLinkageForm form={personalForm.form} isEdit='0'/>
			</div>
		);
		const components = [personInfo];

		if (cPage === 'loan') {
			const loanInfo = <CollapseForm form={conditionForm.form}/>;
			components.push(loanInfo);
		}
		return components;
	}

	getStepTwoInfo = () => {
		const {
			store
		} = this.props, {
			conditionForm,
			cPage
		} = store;

		const conditionInfo = <CollapseForm form={conditionForm.form}/>;

		const components = [conditionInfo];

		if (['childEducation', 'supportOlder'].includes(cPage)) {
			const tableInfo = (
				<TableUnderSearchGroup store={store}/>
			)
			components.push(tableInfo);
		}

		return components;
	}

	getStepThreeInfo = () => {

	}

	render() {
		const {
			store
		} = this.props, {
			cPage,
			SEARCHGROUPS,
			personalForm,
			conditionForm,
			step,
			modify,
			TAXDEDUCTIONITEMS,
		} = store, {
			currentIndex
		} = step;

		//首页
		if (cPage === 'main') {
			return <Menus menus={SEARCHGROUPS} />;
		}

		//个人信息
		if (cPage === 'personalInfo') {
			const {
				form,
				isEdit
			} = personalForm;

			return <NoLinkageForm form={form} isEdit={isEdit}/>;
		}

		//家庭成员
		if (cPage === 'familyMember') {
			return (
				<div>
					<Tab store={store} />
					<Table store={store} />
				</div>
			)
		}

		//专项附加扣除项目
		if (TAXDEDUCTIONITEMS.includes(cPage)) {
			return (
				<div>
					<Step store={store}/>
					{
						this.getInfo(currentIndex)
					}
				</div>
			)

		}

	}
}