import React from 'react';
import {
	inject,
	observer,
} from 'mobx-react';
import {
	WeaFormItem,
	WeaSearchGroup,
	WeaLocaleProvider
} from 'ecCom';
import Table from './Table';
import {
	MagicForm,
} from '../../public/sweet-form.js';
import {
	IconButton,
} from '../../public/learn.js';
import {
	confirmation,
} from '../../util/save-time-util.js';
const getLabel = WeaLocaleProvider.getLabel;

@inject('hrmStaffCareReminder')
@observer
export default class AdminRemind extends React.Component {
	constructor(props) {
		super(props);
	}

	handleIconBtnClick = (index) => {
		const {
			hrmStaffCareReminder
		} = this.props, {
			deleteSysMember,
			table
		} = hrmStaffCareReminder, {
			comsWeaTableStore
		} = table;

		if (index === 0) {
			['openDialog', 'getAuthForm'].map(f => {
				this.props.hrmStaffCareReminder[f]();
			});
		} else {
			if (comsWeaTableStore.selectedRowKeys.length === 0) return

			confirmation.showDelConfirm({
				type: 1,
				logic: () => this.props.hrmStaffCareReminder.deleteSysMember()
			});
		}
	}

	render() {
		const {
			hrmStaffCareReminder
		} = this.props, {
			formElements,
			table,
			forceFresh,
		} = hrmStaffCareReminder, {
			form,
			explain,
		} = formElements, {
			comsWeaTableStore
		} = table;

		const wrapperStyle = {
			padding: '0 25%'
		};

		return <div>
			{
				[getLabel(386231, '管理员提醒'), getLabel(17869, '管理员设置')].map((label, index) => {
					let children;
					if (index === 0) {
						children = (
							<div>
								<MagicForm ecId={`${this && this.props && this.props.ecId || ''}_MagicForm@dluunv@${index}`} {...formElements} isFormInit={form.isFormInit} wrapperStyle={wrapperStyle}/>
								{
									form.isFormInit && explain.map((epl, index) => {
										const {
											showname,
											showvalues
										} = epl;

										return (<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@9uu30y@${index}`}
								            label={showname}
								            labelCol={{span: 6}}
								            wrapperCol={{span: 18}}
								            style={wrapperStyle}
          								>
          									{showvalues.map(sp => <p>{sp}</p>)}
          								</WeaFormItem>)
									})
								}
								
							</div>
						)
					} else {
						children = <Table ecId={`${this && this.props && this.props.ecId || ''}_Table@1gsbsm@${index}`} />
					}

					return <WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@rvzuvl@${index}`} title={label} children={children} customComponent={index === 1 ? <IconButton ecId={`${this && this.props && this.props.ecId || ''}_IconButton@quak5b@${index}`} tableStore={comsWeaTableStore} handleIconBtnClick ={index => this.handleIconBtnClick(index)}/> : ''} showGroup/>
				})
			}
		</div>

	}
}