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 {WeaTable } from "ecCom";
import "../../style/sanyuanLog.less";

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

	componentDidMount() {
		this.initPage();
	}

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

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

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

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

		return (
			<div className="hrm-sanyuan-log">
				<Authority ecId={`${this && this.props && this.props.ecId || ''}_Authority@pdhvmh`} store={authorityStore}>
					<Top ecId={`${this && this.props && this.props.ecId || ''}_Top@47occk`} store={topStore}>
						<Search ecId={`${this && this.props && this.props.ecId || ''}_Search@1k3vc9`} store={searchStore}/>
						<RadioGroup ecId={`${this && this.props && this.props.ecId || ''}_RadioGroup@0qrtcl`} store={normalLogStore}/>
						<Table ecId={`${this && this.props && this.props.ecId || ''}_Table@lylbjn`} store={tableListStore}/>
					</Top>
					{dialogStore.visible && (
						<Dialog ecId={`${this && this.props && this.props.ecId || ''}_Dialog@1ak2rm`} store={dialogStore}>
							{this.getDialogContent()}
						</Dialog>
					)}
				</Authority>
			</div>
		);
	}
}