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

import {
	Spin,
	message,
} from 'antd'

import Editor from './Editor'

import {
	HocFactory
} from './HocFactory'

const JobGroupEditor = HocFactory(Editor, 'jobGroup');
const JobEditor = HocFactory(Editor, 'job');

@inject('hrmSingleJobFormStore')
@observer
export default class SingleJob extends React.Component {
	constructor(props) {
		super(props);
	}

	componentWillMount() {
		const {
			hrmSingleJobFormStore
		} = this.props, {
			setJobId
		} = hrmSingleJobFormStore;

		setJobId(this.props.location.query.id);
	}

	componentDidMount() {
		const {
			hrmSingleJobFormStore
		} = this.props, {
			getRight,
			setParentHideMthd,
		} = hrmSingleJobFormStore;

		getRight();
		this.props.onRef && this.props.onRef(this);
		setParentHideMthd(this.props.hide)
	}

	save = () => {
		const {
			hrmSingleJobFormStore
		} = this.props, {
			saveJobForm,
		} = hrmSingleJobFormStore;

		saveJobForm();
	}

	render() {
		const {
			hrmSingleJobFormStore
		} = this.props, {
			job,
			jobGroup,
			setJobGroupDialogVisible,
			saveJobGroupForm,
			date,
		} = hrmSingleJobFormStore;

		return (
			<div>
				<JobEditor {...job} isFormInit={job.form.isFormInit} plusClick={() => setJobGroupDialogVisible(true)} />
				{jobGroup.visible && <JobGroupEditor 
										{...jobGroup} 
										isFormInit={jobGroup.form.isFormInit} 
										saveJobGroupForm={() => saveJobGroupForm()} 
										closeDialog={() => setJobGroupDialogVisible(false)}
									 />
				}
			</div>
		)

	}
}