import React from 'react';
import {
	inject,
	observer,
} from 'mobx-react';
import Top from './Top';
import Content from './Content';
import Dialog from './Dialog';
import Import from '../importRelatedComponet/index';
import '../../style/newPost.less';

@inject('hrmImportCommon')
@inject('hrmNewPost')
@observer
export default class NewPost extends React.Component {
	constructor(props) {
		super(props);
	}

	componentWillMount () {
		const {
			hrmNewPost: store,
			hrmImportCommon
		} = this.props;

		store.exportStore(hrmImportCommon, store);
	}

	componentWillReceiveProps (nextProps) {
		const { hrmNewPost } = this.props
		if (this.props.location.key !== nextProps.location.key) {
			this.init();
			hrmNewPost.onSearchHandleMobx()
		}
	}

	componentDidMount () {
		const { hrmNewPost } = this.props
		this.init();
		hrmNewPost.onSearchHandleMobx()
	}

	init = () => {
		const {
			hrmNewPost: store
		} = this.props;

		store.refresh();
	}

	render () {
		const {
			hrmImportCommon,
			hrmNewPost: store,
		} = this.props, {
			dialog,
		} = store, {
			importDialog
		} = hrmImportCommon;

		return (
			<div className='post'>
				<Top ecId={`${this && this.props && this.props.ecId || ''}_Top@bfrfwp`} store={store}>
					<Content ecId={`${this && this.props && this.props.ecId || ''}_Content@meicyl`} store={store} />
				</Top>
				{
					dialog.visible && <Dialog ecId={`${this && this.props && this.props.ecId || ''}_Dialog@eoafcg`}
						store={store}
						dialogSpecial={dialog} />
				}
				{importDialog.visible && <Import ecId={`${this && this.props && this.props.ecId || ''}_Import@dkoh8h`} />}
			</div>
		);
	}

}