import {
	inject,
	observer,
} from 'mobx-react'
import {
	toJS
} from 'mobx'
import {
	WeaDialog,
	WeaMoreButton
} from 'ecCom'
import {
	Modal,
	Button,
} from 'antd'
import {
	i18n
} from '../../public/i18n';
const confirm = Modal.confirm;

import ItemsSet from './ItemsSet';

@inject('hrmSalaryItemsSet')
@observer
export default class MainDialog extends React.Component {
	constructor(props) {
		super(props);
		this.state = {
			width: 1100,
			height: 1000,
		}
	}

	getButtons = () => {
		const {
			hrmSalaryItemsSet
		} = this.props, {
			formInfo,
			common,
		} = hrmSalaryItemsSet;

		const sv = (<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@mf7w51`} type="primary" disabled={formInfo.loading || common.loading} onClick={() => this.save()}>{i18n.button.save()}</Button>);

		const mr = (<WeaMoreButton ecId={`${this && this.props && this.props.ecId || ''}_WeaMoreButton@xf9zst`} />);

		const btns = [sv, mr];

		return btns;
	}

	save = () => {
		const {
			hrmSalaryItemsSet
		} = this.props, {
			formInfo,
			saveSalary,
			saveTaxRevenue,
			saveFormulaDatas,
		} = hrmSalaryItemsSet, {
			itemType
		} = formInfo;

		switch (itemType) {
			case '1':
				saveSalary();
				break;
			case '3':
			case '11':
				saveTaxRevenue();
				break;
			default:
				saveFormulaDatas();
		}
	}


	render() {
		const {
			hrmSalaryItemsSet
		} = this.props, {
			closeDialog,
			mainDialog,
			mainTable,
		} = hrmSalaryItemsSet, {
			title,
			visible,
		} = mainDialog, {
			width,
			height,
		} = this.state;

		return (
			<WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@m1w7fz`}
	          	title={title}
	          	icon="icon-coms-hrm"
	          	iconBgcolor="#217346"
	          	visible={visible}
	          	closable={true}
	          	hasScroll={true}
	          	onCancel={() => closeDialog()}
	          	buttons={this.getButtons()}
	          	style={{width: width, height: height}}
	          	onChangeHeight={(h) => this.setState({height: h})}
	        >
	          	{visible && <ItemsSet ecId={`${this && this.props && this.props.ecId || ''}_ItemsSet@kj8uyd`} />}
	        </WeaDialog>
		)

	}
}