/** @format */

import * as React from 'react';
import Analysis from '../components/analysisChart';
import {useMerchantProvideAnalysis} from '../../../../service/merchant';
import Search from '../components/search';
import Modal from '../../../../components/modalForm';
const Result: React.FC = props => {
    const {children} = props;
    const [provideAnalysisState, requestProvideAnaly, clear] = useMerchantProvideAnalysis();
    const handleSearch = (values: any) => {
        requestProvideAnaly(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} />
                <Analysis loading={provideAnalysisState.loading} dataSource={provideAnalysisState.dataSource} />
            </Modal>
        </React.Fragment>
    );
};
export default Result;
