import React ,{
	Component
}from 'react';
import {
	WeaTools,
	WeaDialog,
	WeaLocaleProvider
} from 'ecCom';
import {
	Button,
	message
} from 'antd';
import ReactDOM from 'react-dom';
const getLabel = WeaLocaleProvider.getLabel;

const check = (params) => {
	return WeaTools.callApi('/api/kq/setupwizard/checkNeedInit', 'GET', params);
}

export const checkNeedInit = (onOk) => {
	check().then(datas => {
		const {
			status,
			message,
		} = datas;

		if (status === "2") {
			const div = document.createElement("div");
			document.body.appendChild(div);
			ReactDOM.render(<UpgrageConfirm ecId={`${this && this.props && this.props.ecId || ''}_UpgrageConfirm@c8klle`} message={message} onOk={onOk}/>, div);
		} else {
			onOk();
		}
	}).catch(() => {
		message.warning();
	})
}

class UpgrageConfirm extends Component{
	constructor(props){
		super(props);

		this.state = {
			visible:false
		}
	}

	componentDidMount() {
		this.setState({visible:true});
	}

	handleOk = () => {
		this.props.onOk && this.props.onOk();
		this.handleCancel();
	}

	handleCancel = () => {
		this.setState({visible:false});
	}

	getButtons = () => {
		return[
			<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@7ef8ou`} onClick={this.handleOk} type="primary">{getLabel(33703, '确定')}</Button>,
		]

	}

	render() {
		const {
			visible
		} = this.state, {
			message
		} = this.props;

		const pstyle = {
			display: "table-cell",
			verticalAlign: "middle",
			padding: "0 15px"
		}

		if (!visible) {
			return null;
		}

		return (
			<WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@a5c9nv`} 
				hasScroll
                title={getLabel(131329, '信息确认')}
                icon="icon-coms02-Warning"
                iconBgcolor="#ff9900"
                visible={visible}
                style={{width:380,height:100}}
                onCancel={this.handleCancel}
                buttons={this.getButtons()}
            >
            	<div style={{height:"100%",display: "table",margin: "0 auto"}}>
	              <p style={pstyle} dangerouslySetInnerHTML={{__html: message}} />
            	</div>
            </WeaDialog>
		);
	}
}