import React, {
	Component
} from 'react';
import {
	observer
} from 'mobx-react';
import {
	WeaNewScroll,
	WeaRightMenu,
	WeaDialog
} from 'ecCom';
import {
	Form,
	Button,
	message
} from 'antd';
import {
	WeaTableNew
} from 'comsMobx';
import classnames from 'classnames';
import {
	findIndex
} from 'lodash';
import {
	showAuthorizationRefs
} from '../../util/pulic-func';
import RoleEditDialog from '../role/RoleEditDialog';

const {
	WeaTable
} = WeaTableNew;

@observer
export default class AuthorizationList extends Component {
	constructor(props){
		super(props);
	}

	componentDidMount = () => {}

	doShow = (id, record) => {
		const {
			store
		} = this.props;
		const {
			showRoleEditDialog,
			showRefs
		} = store;
		//TODO
		//showAuthorizationRefs(store.opId, 0, id);

		// showRoleEditDialog({
		// 	roleId: 1782
		// }, '2');
		showRefs(id, record.rightnamespan, this.props.height || $(document).height());
	}

	doDel = (id) => {
		const {
			store
		} = this.props, {
			removeGroupAuthorizatioRela,
			opId
		} = store;
		removeGroupAuthorizatioRela({
			id,
			groupID: opId
		});
	}

	onOperatesClick = (record, index, operate) => {
		const func = operate.href ? operate.href.split(':')[1].split('(')[0] : '';
		const id = record.id ? record.id : '';
		this[func] && this[func](id, record);
	}

	renderCol = (cols) => {
		let idx = findIndex(cols, item => item.dataIndex === 'rightname');
		idx != -1 && (cols[idx].render = (text, record) => {
			return <a onClick={() => this.doShow(record.id, record)}>{record.rightnamespan}</a>
		})
	}

	render() {
		const {
			store,
			rightMenu
		} = this.props, {
			authorizationListTable: table,
			save,
			dialogParams,
			roleEditDialogParams,
			refreshDialog,
			roleRefsDialogParams
		} = store;
		const {
			editGroupInfo
		} = dialogParams;
		const classes = classnames({
			['tabPane']: true,
			['tabPane-dialog']: editGroupInfo.visible
		});

		let scrollProps = {};
		editGroupInfo.visible && Object.assign(scrollProps, {
			scroll: {
				y: (this.props.height != null ? (this.props.height - 140) : 510)
			}
		})

		return (
			<div className={classes}>
                <WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@03g25r`} datas={[]}>
                    <WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@jsjzf7`}
                        comsWeaTableStore={table}
                        hasOrder={true}
                        needScroll={true}
                        {...scrollProps}
                        onOperatesClick={(record, index, operate) => this.onOperatesClick(record, index, operate)}
                        getColumns={cols => this.renderCol(cols)}
                    />
                </WeaRightMenu>
				<WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@uaflzl`} {...roleRefsDialogParams} />
            </div>
		)
	}
}