export interface DaySummary { date: string count: number first_ts?: string last_ts?: string } export interface Trackpoint { event_id: string device_id: string trip_id: string timestamp: string lat: number lon: number source: 'gps' | 'manual' note?: string } export interface Stop { stop_id: string device_id: string trip_id: string start_ts: string end_ts: string center_lat: number center_lon: number duration_s: number place_label?: string } export interface Suggestion { suggestion_id: string stop_id: string type: 'highlight' | 'name_place' | 'add_note' title: string text: string created_at: string dismissed_at?: string } async function get(path: string): Promise { const res = await fetch(path, { credentials: 'include' }) if (res.status === 401) { window.location.href = '/login' throw new Error('unauthenticated') } if (!res.ok) throw new Error(`${res.status} ${res.statusText}`) return res.json() as Promise } export const api = { getDays(from?: string, to?: string): Promise { const now = new Date() const defaultTo = now.toISOString().slice(0, 10) const past = new Date(now) past.setDate(past.getDate() - 90) const defaultFrom = past.toISOString().slice(0, 10) const params = new URLSearchParams({ from: from ?? defaultFrom, to: to ?? defaultTo, }) return get(`/v1/days?${params}`) }, getTrackpoints(date: string): Promise { return get(`/v1/trackpoints?date=${date}`) }, getStops(date: string): Promise { return get(`/v1/stops?date=${date}`) }, getSuggestions(date: string): Promise { return get(`/v1/suggestions?date=${date}`) }, }