import React from 'react';
import {
	inject,
	observer
} from 'mobx-react';
import {
	WeaLocaleProvider
} from 'ecCom';
import Base from './Base';
import * as asyncFetch from '../../apis/posts';
const getLabel = WeaLocaleProvider.getLabel;
const {
	getLocaleLabelByCode
} = WeaLocaleProvider;

@inject('hrmBrowseBoxLinkPage')
@observer
export default class Posts extends React.Component {
	constructor(props) {
		super(props);
		this.state = {
			reRender: false
		}
	}

	componentWillMount() {
		const {hrmBrowseBoxLinkPage:{setPage}} = this.props;

		setPage("post");
	}

	componentDidMount() {
		getLocaleLabelByCode('hrm').then(() =>{
			document.title = getLabel('391225', "岗位")
			this.setState({
				reRender: true
			})
		} );
		['setTopTitle', 'getFormElements'].map((f, i) => {
			let params;
			if (i === 0) {
				params = {
					title: () => getLabel('391225', "岗位")
				}
			} else {
				params = {
					asyncFetch,
					fetchParams: {
						jobtitleid: this.props.location.query.id
					}
				};
			}

			this.props.hrmBrowseBoxLinkPage[f](params);
		});
	}

	render() {
		if (!this.state.reRender)
			return <div />
		return (
			<Base ecId={`${this && this.props && this.props.ecId || ''}_Base@297h0z`} type={this.props.location.query.type}/>
		)
	}
}