import React, {
	Component
} from 'react';
import {
	observer,
	inject
} from 'mobx-react';
import {
	toJS
} from 'mobx';
import {
	Authority,
	Top,
	Search,
	RadioGroup,
	Table,
	Dialog,
} from '../../public/valhalla/components/index.js';
import { WeaTableEditable,WeaTable } from "ecCom";
import "../../style/sanyuanLog.less";

@inject('secAdminLogStore')
@observer
export default class SecAdminLog extends Component {
	componentWillReceiveProps(nextProps) {
		if (this.props.location.key !== nextProps.location.key) {
			this.initPage();
		}
	}

	componentDidMount() {
		this.initPage();
	}

	initPage = () => {
		this.props.secAdminLogStore.initPage();
	}

	getDialogContent = () => {
		const {
			secAdminLogStore
		} = this.props, {
			logDetail,
			isLogDetail,
			originParams,
			columns,
			datas,
		} = secAdminLogStore;

		return (
			<React.Fragment ecId={`${this && this.props && this.props.ecId || ''}_undefined@806e2w`}>
				{
					isLogDetail ?( logDetail && logDetail.map(detail => {
						return (
							<div className="hrm-sanyuan-log-detail">
								<code>{detail}</code>
							</div>
						)
					}) ) : originParams.map(param => {
						return (
							<div className="hrm-sanyuan-log-origin">
								<code>{param}</code>
							</div>
						)
					})
				}
				{
					datas.map( (data,index) => {
						if (data.length > 0) {
							return (
								<div className="hrm-sanyuan-view">
									<WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@isp46l@${index}`}  
										pagination={false} 
										columns={toJS(columns[index])} 
										dataSource={toJS(data)}
										scroll={{ x: 580, y: 330 }}
									/>
								</div>
							)
						}
					})
				}
			</React.Fragment>
		)
	}

	render() {
		const {
			secAdminLogStore
		} = this.props, {
			authorityStore,
			topStore,
			searchStore,
			radioGroupStore,
			tableListStore,
			dialogStore,
		} = secAdminLogStore;

		return (
			<div className="hrm-sanyuan-log">
				<Authority ecId={`${this && this.props && this.props.ecId || ''}_Authority@26t5ql`} store={authorityStore}>
					<Top ecId={`${this && this.props && this.props.ecId || ''}_Top@3zrs9t`} store={topStore}>
						<Search ecId={`${this && this.props && this.props.ecId || ''}_Search@rblbib`} store={searchStore}/>
						<RadioGroup ecId={`${this && this.props && this.props.ecId || ''}_RadioGroup@otxfyu`} store={secAdminLogStore}/>
						<Table ecId={`${this && this.props && this.props.ecId || ''}_Table@pd03pt`} store={tableListStore}/>
					</Top>
					{dialogStore.visible && (
						<Dialog ecId={`${this && this.props && this.props.ecId || ''}_Dialog@philwd`} store={dialogStore}>
							{this.getDialogContent()}
						</Dialog>
					)}
				</Authority>
			</div>
		);
	}
}