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('systemAdminLogStore')
@observer
export default class SystemAdminLog extends Component {
	componentWillReceiveProps(nextProps) {
		if (this.props.location.key !== nextProps.location.key) {
			this.initPage();
		}
	}

	componentDidMount() {
		this.initPage();
	}

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

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

		return (
			<React.Fragment ecId={`${this && this.props && this.props.ecId || ''}_undefined@ohqiey`}>
				{
					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@wml1vd@${index}`}  
										pagination={false} 
										columns={toJS(columns[index])} 
										dataSource={toJS(data)}
										scroll={{ x: 580, y: 330 }}
									/>
								</div>
							)
						}
					})
				}
			</React.Fragment>
		)
	}

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

		return (
			<div className="hrm-sanyuan-log">
				<Authority ecId={`${this && this.props && this.props.ecId || ''}_Authority@kqjqtf`} store={authorityStore}>
					<Top ecId={`${this && this.props && this.props.ecId || ''}_Top@jpp8s7`} store={topStore}>
						<Search ecId={`${this && this.props && this.props.ecId || ''}_Search@kvw2yw`} store={searchStore}/>
						<RadioGroup ecId={`${this && this.props && this.props.ecId || ''}_RadioGroup@b5qcow`} store={systemAdminLogStore}/>
						<Table ecId={`${this && this.props && this.props.ecId || ''}_Table@wy7ace`} store={tableListStore}/>
					</Top>
					{dialogStore.visible && (
						<Dialog ecId={`${this && this.props && this.props.ecId || ''}_Dialog@9qzdez`} store={dialogStore}>
							{this.getDialogContent()}
						</Dialog>
					)}
				</Authority>
			</div>
		);
	}
}