import { merge } from "@tachybase/schema";
import { useRequest, useSetState } from "ahooks";
import { cloneDeep } from "lodash";
import { assign as external_assign_mjs_assign } from "./assign.mjs";
import { useAPIClient } from "./useAPIClient.mjs";
function useRequest_useRequest(service) {
    let options = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {};
    const [state, setState] = useSetState({});
    const api = useAPIClient();
    let tempService;
    tempService = 'function' == typeof service ? service : service ? async function() {
        let params = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
        const { resource, url } = service;
        let args = cloneDeep(service);
        if (resource || url) {
            args.params = args.params || {};
            external_assign_mjs_assign(args.params, params);
        } else args = merge(args, params);
        const response = await api.request(args);
        return null == response ? void 0 : response.data;
    } : async ()=>{};
    const tempOptions = {
        ...options,
        onSuccess () {
            for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++)args[_key] = arguments[_key];
            var _options_onSuccess;
            null == (_options_onSuccess = options.onSuccess) || _options_onSuccess.call(options, ...args);
            if (options.uid) api.services[options.uid] = result;
        }
    };
    const result = useRequest(tempService, tempOptions);
    return {
        ...result,
        state,
        setState
    };
}
export { useRequest_useRequest as useRequest };
