import React, {
	Component
} from 'react';
import {
	WeaNewScroll
} from 'ecCom';
import Tabs from '../../coms/Tabs';
import FormInfo from '../../coms/FormInfo';
import AuthorizationList from './AuthorizationList';
import {
	inject,
	observer
} from 'mobx-react';
import {
	i18n
} from '../../public/i18n';

export default class AuthorizationGroupEditTab extends Component {
	constructor(props) {
		super(props);
	}

	tabChangeHandle = (key) => {
		const {
			store
		} = this.props, {
			editGroupTabConfig
		} = store;
		store.setActiveTab(editGroupTabConfig, key);
	}

	render() {
		const {
			store
		} = this.props, {
			editGroupTabConfig,
			getTabIndex,
			btnsAndMenus,
			formTarget,
			dialogParams,
			menuIconCollection,
			saveAuthorizationGroup
		} = store;
		const {
			btns,
			menus,
			tabBtnDef
		} = btnsAndMenus(editGroupTabConfig);
		const activeTabInfo = {
			activeTabKey: editGroupTabConfig.activeTabKey,
			activeTabIndex: getTabIndex(editGroupTabConfig.tabs, editGroupTabConfig.activeTabKey)
		}
		const {
			authorizationGroupForm,
			authorizationGroupFormFields,
			authorizationListConditionForm: conditionForm,
			authorizationListConditionFormFields: conditionFormFields
		} = formTarget;

		const tabProps = {
			tabConfig: editGroupTabConfig,
			tabChangeHandle: this.tabChangeHandle,
			activeTabInfo: {
				activeTabKey: editGroupTabConfig.activeTabKey,
				activeTabIndex: getTabIndex(editGroupTabConfig.tabs, editGroupTabConfig.activeTabKey)
			},
			rightMenu: menus,
			store: store,
			conditionForm: conditionForm,
			conditionFormFields: conditionFormFields,
			tabBtnDef: tabBtnDef
		}

		const formInfoRightMenu = [{ //组织右键菜单
			key: '1',
			content: i18n.button.save(),
			icon: <i className={menuIconCollection.save}/>,
			onClick: () => saveAuthorizationGroup(false, false)
		}]

		return (
			<div>
                <Tabs ecId={`${this && this.props && this.props.ecId || ''}_Tabs@6xgrkp`} {...tabProps}>
                    <FormInfo ecId={`${this && this.props && this.props.ecId || ''}_FormInfo@wtnyxn`} 
                    	className="tabPane tabPane-dialog" 
                    	form={authorizationGroupForm}
                    	formFields={authorizationGroupFormFields}
                    	menu={formInfoRightMenu}/>
                    <AuthorizationList height={this.props.height} ecId={`${this && this.props && this.props.ecId || ''}_AuthorizationList@37zkwk`}/>
                </Tabs>
			</div>
		);
	}
}