import {
	inject,
	observer,
} from 'mobx-react'
import {
	toJS
} from 'mobx'
import {
	WeaTop,
} from 'ecCom'
import {
	i18n
} from '../../public/i18n';

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

	componentDidMount() {
		this.props.hrmAssImple.getButtonsMenu();
	}

	getDropMenuDatas = () => {
		const {
			hrmAssImple
		} = this.props, {
			menu
		} = hrmAssImple, {
			rightMenu
		} = menu;

		let menus = [];
		toJS(rightMenu).map((item, index) => {
			let obj = {
				key: item.menuFun,
				icon: <i className={`${item.menuIcon}`}/>,
				content: item.menuName,
			}
			if (item.menuFun == 'collection' || item.menuFun == 'help' || item.menuFun == 'pageAddress') {
				obj.disabled = true;
			}
			menus.push(obj);
		})

		return menus;
	}

	handleMenuClick = (key) => {
		const {
			hrmAssImple
		} = this.props, {
			mainTab,
			changeSearchPanelStatus
		} = hrmAssImple, {
			isPanelShow
		} = mainTab;

		isPanelShow && changeSearchPanelStatus(false);
		this[key] && this[key]();
	}

	custom = () => {
		const {
			hrmAssImple
		} = this.props, {
			mainTable,
		} = hrmAssImple, {
			tableStore
		} = mainTable;

		tableStore.setColSetVisible(true);
		tableStore.tableColSet(true);
	}

	render() {
		const {
			hrmAssImple
		} = this.props, {
			main
		} = hrmAssImple, {
			title,
		} = main;

		return (
			<WeaTop ecId={`${this && this.props && this.props.ecId || ''}_WeaTop@lzuw0i`} 
				title={title}
				icon={<i className='icon-coms-hrm'/>}
				iconBgcolor='#217346'
				loading={true}
				buttons={[]}
				showDropIcon={true}
				dropMenuDatas={this.getDropMenuDatas()}
				onDropMenuClick={e => this.handleMenuClick(e)}
			>
				{this.props.children}
			</WeaTop>
		)

	}
}