import * as __WEBPACK_EXTERNAL_MODULE__tachybase_schema__ from "@tachybase/schema";
import * as __WEBPACK_EXTERNAL_MODULE_ahooks__ from "ahooks";
import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash";
import * as __WEBPACK_EXTERNAL_MODULE__assign_mjs__ from "./assign.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__useAPIClient_mjs__ from "./useAPIClient.mjs";
function useRequest(service) {
    let options = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {};
    const [state, setState] = (0, __WEBPACK_EXTERNAL_MODULE_ahooks__.useSetState)({});
    const api = (0, __WEBPACK_EXTERNAL_MODULE__useAPIClient_mjs__.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 = (0, __WEBPACK_EXTERNAL_MODULE_lodash__.cloneDeep)(service);
        if (resource || url) {
            args.params = args.params || {};
            (0, __WEBPACK_EXTERNAL_MODULE__assign_mjs__.assign)(args.params, params);
        } else args = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.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) || void 0 === _options_onSuccess || _options_onSuccess.call(options, ...args);
            if (options.uid) api.services[options.uid] = result;
        }
    };
    const result = (0, __WEBPACK_EXTERNAL_MODULE_ahooks__.useRequest)(tempService, tempOptions);
    return {
        ...result,
        state,
        setState
    };
}
export { useRequest };
