/** @format */

import * as React from 'react';
import Analysis from '../components/analysisChart';
import {useResultAnalysis} from '../../../../service/merchant';
import StatusSelect from '../../../../components/select/resultSelect';
import Search from '../components/search';
import Modal from '../../../../components/modalForm';
const Result: React.FC = props => {
    const {children} = props;
    const [resultState, requestResult, clear] = useResultAnalysis();
    const handleSearch = (values: any) => {
        requestResult(values);
    };
    const [state, setState] = React.useState({
        visible: false,
        disableSearch: true,
    });
    const handleUpdateModalVisible = () => {
        setState(preState => {
            if (!!preState.visible) {
                clear();
            }
            return {...preState, visible: !preState.visible};
        });
    };
    return (
        <React.Fragment>
            {React.isValidElement(children) &&
                React.cloneElement(children, {
                    onClick: handleUpdateModalVisible,
                })}
            <Modal
                footer={null}
                visible={state.visible}
                onCancel={handleUpdateModalVisible}
                width={1200}
                title='结果分析'
            >
                <Search
                    onSearch={handleSearch}
                    seacrhColums={[
                        {
                            key: 'status',
                            col: {
                                xxl: 4,
                                lg: 4,
                            },
                            options: {
                                initialValue: 0,
                            },
                            component: <StatusSelect />,
                        },
                    ]}
                />
                <Analysis loading={resultState.loading} dataSource={resultState.dataSource} />
            </Modal>
        </React.Fragment>
    );
};
export default Result;
