import { API_BASE } from '@/config/index.ts'; interface FetchOptions { method?: 'GET' | 'POST'; body?: Record; } export async function apiClient( endpoint: string, options: FetchOptions = {} ): Promise { const { method = 'GET', body } = options; const config: RequestInit = { method, headers: body ? { 'Content-Type': 'application/json' } : undefined, body: body ? JSON.stringify(body) : undefined, }; const response = await fetch(`${API_BASE}${endpoint}`, config); if (!response.ok) { throw new Error(`API Error: ${response.status}`); } return response.json(); } export async function apiClientSafe( endpoint: string, options: FetchOptions = {}, fallback: T ): Promise { try { return await apiClient(endpoint, options); } catch { console.error(`API call failed: ${endpoint}`); return fallback; } }