import {
	observer
} from 'mobx-react';
import {
	MagicForm,
} from '../../public/sweet-form.js';

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

	handleFormChange = (data, form) => {
		const key = Object.keys(data)[0];
		const value = data[key].value;

		//清空分部浏览按钮
		if (key === 'scopeType' && value === '0') {
			form.updateFields({
				'scopeValue': []
			});
		}

		//重置日折算时长
		if (key === 'computingMode' && value === '1') {
			form.updateFields({
				'hoursToDay': {
					value: 8
				}
			});
		}

		if (key === 'minimumUnit') {
			this.props.store.onHolidayUnitChange(value);
		}
	}

	render() {
		const {
			store
		} = this.props, {
			dialog,
			FORMCONFIG,
			dynamicTips,
			renderBlacklist,
		} = store, {
			form
		} = dialog;

		return (
			<MagicForm ecId={`${this && this.props && this.props.ecId || ''}_MagicForm@kphltr`} 
    			{...dialog} 
    			{...FORMCONFIG}
    			isFormInit={form.isFormInit}
    			dynamicTips={dynamicTips}
    			renderBlacklist={renderBlacklist}
    			onFormElementsChange={data => this.handleFormChange(data,form)}
    		 />
		);
	}
}