'use strict';
import { useState } from 'react';
import { apiDelete, apiPut, apiPost, apiGetWithOData, apiGet } from '../api-client.js';
import { httpMethods } from '../../../base-repo/constants/http-methods.js';
import { useApiErrors } from './api-client-constants.js';
import { useAsyncEffect } from '../../hooks/use-async-effect.js';
import { createError } from '../../errors/errors.js';

var __defProp=Object['defineProperty'],__name=(_0x5f08cd,_0x42929f)=>__defProp(_0x5f08cd,'name',{'value':_0x42929f,'configurable':!![]});function useApiGet(_0x53759d){return useApi(httpMethods['get'],_0x53759d);}__name(useApiGet,'useApiGet');function useApiPost(_0x19761a){return useApi(httpMethods['post'],_0x19761a);}__name(useApiPost,'useApiPost');function useApiPut(_0x212bad){return useApi(httpMethods['put'],_0x212bad);}__name(useApiPut,'useApiPut');function useApiDelete(_0x3f9bef){return useApi(httpMethods['delete'],_0x3f9bef);}__name(useApiDelete,'useApiDelete');function useApi(_0x29da2b,_0x5ca98a){const [_0xbef172,_0x1bd25c]=useState(void(0x31*0x2b+0x9*0x1e6+-0x1951*0x1)),[_0x2b4d88,_0x3a7293]=useState(![]),[_0x372c55,_0x55d67c]=useState(void(0x1f22+0x291*-0xa+-0x578)),_0x496df7=__name(async()=>{_0x3a7293(!![]),_0x55d67c(void(-0x16aa+-0x926+0x1fd0));try{let _0x5b23d9;switch(_0x29da2b){case httpMethods['get']:_0x5ca98a['oDataConfig']&&(_0x5b23d9=await apiGetWithOData(_0x5ca98a['endpoint'],_0x5ca98a['oDataConfig'],_0x5ca98a['id']));_0x5b23d9=await apiGet(_0x5ca98a['endpoint'],_0x5ca98a['id'],_0x5ca98a['queryParams'],_0x5ca98a['headers']),_0x1bd25c(_0x5b23d9);break;case httpMethods['post']:_0x5b23d9=await apiPost(_0x5ca98a['endpoint'],_0x5ca98a['data'],_0x5ca98a['headers']),_0x1bd25c(_0x5b23d9);break;case httpMethods['put']:if(!_0x5ca98a['data'])throw createError(useApiErrors['noDataProvided']);_0x5b23d9=await apiPut(_0x5ca98a['endpoint'],_0x5ca98a['data'],_0x5ca98a['headers']),_0x1bd25c(_0x5b23d9);break;case httpMethods['delete']:if(!_0x5ca98a['id'])throw createError(useApiErrors['noIdProvided']);await apiDelete(_0x5ca98a['endpoint'],_0x5ca98a['id'],_0x5ca98a['headers']);break;default:throw createError(useApiErrors['unsupportedRequestName']);}}catch(_0x59c7b6){_0x55d67c(_0x59c7b6);}finally{_0x3a7293(![]);}},'fetchData');return useAsyncEffect(async()=>{await _0x496df7();},[_0x29da2b,_0x5ca98a]),{'data':_0xbef172,'isLoading':_0x2b4d88,'error':_0x372c55,'refetch':_0x496df7};}__name(useApi,'useApi');

export { useApiDelete, useApiGet, useApiPost, useApiPut };
