import { WiFiHotspot } from '../types'; const API_Base_URL = '/api/markers'; export const apiService = { getHotspots: async (): Promise => { try { const response = await fetch(API_Base_URL); if (!response.ok) throw new Error('Failed to fetch markers'); const data = await response.json(); return data; } catch (e) { console.error("Failed to load hotspots from API", e); return []; } }, saveHotspot: async (hotspot: WiFiHotspot): Promise => { try { const response = await fetch(API_Base_URL, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(hotspot), }); if (!response.ok) throw new Error('Failed to save marker'); // Trigger a storage event to refresh UI if needed (keeping compatibility) window.dispatchEvent(new Event('storage_updated')); } catch (e) { console.error("Failed to save hotspot", e); } }, deleteHotspot: async (id: string): Promise => { try { const response = await fetch(`${API_Base_URL}/${id}`, { method: 'DELETE', }); if (!response.ok) throw new Error('Failed to delete marker'); window.dispatchEvent(new Event('storage_updated')); } catch (e) { console.error("Failed to delete hotspot", e); } } };