import { apiClient } from './apiClient'

export interface AnalyticsEvent {
    event_name: 'app_open' | 'screen_view' | 'route_selected' | 'stop_selected' | 'schedule_viewed' | 'reminder_created' | 'promo_view' | 'promo_click' | 'taxi_view' | 'taxi_click' | 'shuttle_view' | 'shuttle_contact' | 'business_view' | 'business_contact' | 'login' | 'sign_up'
    screen_name?: string
    item_id?: string
    properties?: Record<string, any>
}

export const analyticsService = {
    logEvent(event: AnalyticsEvent) {
        // Log asynchronously without awaiting to avoid blocking UI
        apiClient.post('/api/analytics/event', event).catch(error => {
            console.warn('Analytics capture failed:', error)
        })
    },

    async getStats() {
        const response = await apiClient.get('/api/analytics/dashboard/stats')
        return response.data
    }
}
