import React, { Component } from 'react';
import { notification, Alert } from 'antd'

export default function SnackbarHOC(options = {}) {
	return function wrap(WrappedComponent) {
		return class Wrapper extends Component {
			constructor(props) {
				super(props);
				this.showSnackbar = this.showSnackbar.bind(this)
				this.handleSnackbarClose = this.handleSnackbarClose.bind(this)
				this.state = {
					snackbarText: '',
					snackbarOpen: false,
				}
			}

			handleSnackbarClose() {
				this.setState({
					snackbarOpen: false,
					snackbarVertical: '',
					snackbarHorizontal: '',
				})
			}

			showSnackbar(text, vertical, horizontal) {
				this.setState({
					snackbarOpen: true,
					snackbarText: text,
					snackbarVertical: vertical,
					snackbarHorizontal: horizontal,
				})
			}
			//个别情况需要走
			showNotification = (description, message = "提示", icon) => {
				const data = {
					message,
					description
				}
				if (icon) {
					data.icon = icon;
				}
				notification.open(data);
			}
			render() {
				const { snackbarOpen, snackbarText } = this.state

				return (
					<React.Fragment>
						{snackbarOpen ? <Alert messagg={snackbarText} onClose={this.handleSnackbarClose} /> : null}
						<WrappedComponent {...this.props} showSnackbar={this.showSnackbar} showNotification={this.showNotification} >

						</WrappedComponent>
					</React.Fragment>
				)
			}
		}
	}
}