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

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

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

	getTopMenuBtns = () => {
		const {
			hrmConExWarning
		} = this.props, {
			menu,
			table,
		} = hrmConExWarning, {
			tableStore
		} = table;

		let btns = [];

		menu.topMenu.map((item, index) => {
			btns.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@vw970o@${index}`} type='primary' disabled={tableStore.loading} onClick={() => this.handleClick(item)}>{item.menuName}</Button>);
		});
		return btns;
	}

	handleClick = (item) => {
		this[item.menuFun] && this[item.menuFun]()
	}

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

		let menus = [];
		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) => {
		this[key] && this[key]();
	}

	save = () => {
		this.props.hrmConExWarning.save();
	}

	log = () => {
		window.setLogViewProps({
			logSmallType: '3048',
		});
	}

	custom = () => {
		const {
			hrmConExWarning
		} = this.props, {
			table,
		} = hrmConExWarning, {
			tableStore
		} = table;

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

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

		return (
			<WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@2oxhdc`} 
		 		datas={this.getDropMenuDatas()} 
		 		onClick={ key=>this.handleMenuClick(key)}
		 		collectParams={{favname:i18n.module.contractExpireWarning(),favouritetype:5}}
		 	>
				<WeaTop ecId={`${this && this.props && this.props.ecId || ''}_WeaTop@pww8wb`} 
					title={title}
					icon={<i className='icon-coms-hrm'/>}
					iconBgcolor='#217346'
					loading={true}
					buttons={this.getTopMenuBtns()}
					showDropIcon={true}
					dropMenuDatas={this.getDropMenuDatas()}
					onDropMenuClick={e => this.handleMenuClick(e)}
				>
					{this.props.children}
				</WeaTop>
			</WeaRightMenu>
		)

	}
}