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

	componentDidMount() {
		this.initPage();
	}

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

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

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

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

		return (
			<div className="hrm-sanyuan-log">
				<Authority ecId={`${this && this.props && this.props.ecId || ''}_Authority@66kx1l`} store={authorityStore}>
					<Top ecId={`${this && this.props && this.props.ecId || ''}_Top@cyxhmr`} store={topStore}>
						<Search ecId={`${this && this.props && this.props.ecId || ''}_Search@rb4jel`} store={searchStore}/>
						<RadioGroup ecId={`${this && this.props && this.props.ecId || ''}_RadioGroup@f2a7v2`} store={secAuditorLogStore}/>
						<Table ecId={`${this && this.props && this.props.ecId || ''}_Table@m92s77`} store={tableListStore}/>
					</Top>
					{dialogStore.visible && (
						<Dialog ecId={`${this && this.props && this.props.ecId || ''}_Dialog@ki8t6x`} store={dialogStore}>
							{this.getDialogContent()}
						</Dialog>
					)}
				</Authority>
			</div>
		);
	}
}