// Tự động chọn base URL: // - Production (Vercel): dùng VITE_API_URL trỏ về HF Space // - Development (local): dùng '' để Vite proxy forward về localhost:5000 const BASE_URL = import.meta.env.VITE_API_URL || ''; export const api = { get: (path, token = null) => fetch(`${BASE_URL}${path}`, { headers: token ? { Authorization: `Bearer ${token}` } : {} }).then(r => r.json()), post: (path, body, token = null) => fetch(`${BASE_URL}${path}`, { method: 'POST', headers: { 'Content-Type': 'application/json', ...(token ? { Authorization: `Bearer ${token}` } : {}) }, body: JSON.stringify(body) }).then(r => r.json()), put: (path, body, token) => fetch(`${BASE_URL}${path}`, { method: 'PUT', headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` }, body: JSON.stringify(body) }).then(r => r.json()), delete: (path, token) => fetch(`${BASE_URL}${path}`, { method: 'DELETE', headers: { Authorization: `Bearer ${token}` } }).then(r => r.json()), };