import ConfigProvider from '../config-provider';
import React, { Component } from 'react';
import cls from 'classnames';
import zhCN from '../locale/zh-cn';
import { Button } from '../index';
import { Dialog as NextDialog } from '@alifd/next';
class Dialog extends Component {
    render() {
        const { footerAlign, footerActions, className, prefix = 'next-', } = this.props;
        return (React.createElement(NextDialog, Object.assign({}, this.props, { className: cls(className, {
                [`${prefix}dialog-nofooter`]: this.props.footer === false,
            }), footerAlign: !footerAlign ? 'center' : footerAlign, footerActions: !footerActions ? ['cancel', 'ok'] : footerActions })));
    }
}
Dialog.wrapMethod = (type) => (config = {}) => {
    let ret;
    const { onOk, onCancel, onClose } = config;
    config.onOk = () => {
        onOk && onOk();
        ret && ret.hide();
    };
    config.onCancel = () => {
        onCancel && onCancel();
        ret && ret.hide();
    };
    config.onClose = (...args) => {
        onClose && onClose(...args);
        ret && ret.hide();
    };
    if (!config.locale) {
        config.locale = zhCN.Dialog;
    }
    const okBtnChildren = config.okProps
        // @ts-ignore
        ? config.okProps.children
        : config.locale.ok;
    const cancelBtnChildren = config.cancelProps
        ? config.cancelProps.children
        : config.locale.cancel;
    if (type) {
        config.type = type;
    }
    const { footerAlign, footerActions, footer } = config;
    if (!footerAlign) {
        config.footerAlign = 'right';
    }
    if (!footerActions) {
        config.footerActions = type === 'alert' ? ['ok'] : ['cancel', 'ok'];
    }
    if (footer == null) {
        config.footer = [
            React.createElement(Button, { type: "secondary", className: "next-dialog-btn", text: true, size: "small", onClick: config.onCancel }, cancelBtnChildren),
            React.createElement(Button, { type: "secondary", size: "small", className: "next-dialog-btn", onClick: config.onOk }, okBtnChildren),
        ];
    }
    ret = NextDialog[type || 'show'](config);
    return ret;
};
Dialog.show = Dialog.wrapMethod();
Dialog.alert = Dialog.wrapMethod('alert');
Dialog.confirm = Dialog.wrapMethod('confirm');
// @ts-ignore
Dialog.withContext = NextDialog.withContext;
// 这里不能覆盖
// hoistNonReactStatics(Dialog, NextDialog);
export default ConfigProvider.config(Dialog);
