/** @format */

import * as React from 'react';
import {Spin} from 'antd';
import message from '../../../../components/message';
import {decodeBase64} from '../../../../utils/base64';
import InterfaceEditComponet from '../components/interfaceForm';
import {useBaseApiInfo, usePutBaseApi} from '../../../../service/baseApi';
const editInterface: React.FC = () => {
    const id = new URLSearchParams(decodeBase64(location.search.slice(1))).get('id');
    const [infoState, requestInfo] = useBaseApiInfo();
    const [putState, requestPutBaseApi] = usePutBaseApi();
    React.useEffect(() => {
        if (id) {
            requestInfo(Number(id));
        }
    }, [id]);
    const handleSubmit = (values: any) => {
        requestPutBaseApi({
            ...values,
            id: id,
        }).then(error => {
            if (error) {
                return message.error(error);
            }
            return message.success('更新接口成功!');
        });
    };

    return (
        <Spin spinning={infoState.loading}>
            <InterfaceEditComponet onSubmit={handleSubmit} loading={putState.loading} values={infoState.data} />
        </Spin>
    );
};
export default editInterface;
