import { connect } from "umi";
import { ConnectState } from "@/models/global";
import { Button } from "antd";
import Popconfirm from "antd/es/popconfirm";

type DetailProps = {
    hideDelete?: boolean
    handleDelete?: any
    hideCancel?: boolean
    handleCancel?: any
    hideOK?: boolean
    handleOK?: any
    confirmLoading?: boolean // 确认按钮的加载效果
}
const ModalFooter = ({ hideDelete, handleDelete, hideCancel, handleCancel, hideOK, handleOK, confirmLoading }: DetailProps) => {

    return (
        <div style={{ width: '100%', boxSizing: 'border-box', padding: '0 12px', display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
            <div>
                {
                    hideDelete ? "" :
                        <Popconfirm
                            title="确认删除?"
                            onConfirm={async () => {
                                if (handleDelete) {
                                    handleDelete()
                                }
                            }}
                        >
                            <Button type="primary" danger loading={confirmLoading}>删除</Button>
                        </Popconfirm>

                }
            </div>
            <div>
                {
                    hideCancel ? '' :
                        <Button onClick={() => {
                            if (handleCancel) {
                                handleCancel()
                            }
                        }}>取消</Button>
                }
                {
                    hideOK ? '' :
                        <Button type={"primary"} style={{ marginLeft: '8px' }} loading={confirmLoading} onClick={() => {
                            if (handleOK) {
                                handleOK()
                            }
                        }}>确认</Button>
                }
            </div>
        </div>
    )
}

export default connect(({ user }: ConnectState) => ({
    currentUser: user.data
}))(ModalFooter); 