/** @format */

import * as React from 'react';
import AlertSetingComponet, {AlertFormDataProps} from '../../../components/alertSetting';
import {usePutSourceApi} from '../../../service/provideApi';
export interface AlertSetDataProps extends AlertFormDataProps {
    id: number;
    name: string;
    [propIndex: string]: any;
}
interface Iprops {
    visible: boolean;
    data: AlertSetDataProps;
    onCancel: () => void;
    onOk: () => void;
}
const AlertSetingPage: React.FC<Iprops> = props => {
    const [putState, setPutState, requestData] = usePutSourceApi();
    const {onCancel, data, onOk} = props;
    const {threshold_timeout, threshold_fail_rate, threshold_norecord_rate, warning_enable, id} = data;
    const handleSubmit = (values: AlertFormDataProps) => {
        requestData({
            ...values,
            provider_api_id: id,
        }).then(error => {
            if (!error) {
                setPutState(preState => ({...preState, error: null}));
                onOk();
            }
        });
    };
    return (
        <AlertSetingComponet
            submit={handleSubmit}
            error={putState.error}
            onCancel={onCancel}
            data={{
                threshold_timeout,
                threshold_fail_rate,
                threshold_norecord_rate,
                warning_enable,
            }}
            loading={putState.loading}
            visible={props.visible}
            title={`预警设置-${data.name}`}
        />
    );
};
export default AlertSetingPage;
