interface InteractionItem {
    location: string;
    description?: string;
}

export const logActivity = async (interaction: InteractionItem): Promise<void> => {
    try {
        const userId = localStorage.getItem('user');
        const api_url = process.env.API_URL || '';

        if (!userId) {
            console.warn('User ID not found in localStorage');
            return;
        }

        const payload = {
            user_id: userId,
            interaction: [interaction],
        };

        const response = await fetch(`${api_url}api/activity/store`, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
            },
            body: JSON.stringify(payload),
            credentials: 'include',
        });

        if (!response.ok) {
            console.warn('Log activity failed:', await response.json());
        }
    } catch (error) {
        console.error('Error logging activity:', error);
    }
};
