const ALLOWED_LEVELS = ['info', 'warn', 'error'];

export async function clientLog(level, message, meta = {}) {
  if (!ALLOWED_LEVELS.includes(level)) {
    console.warn('clientLog: invalid level, fallback to info', level);
    level = 'info';
  }

  try {
    await $fetch('/api/log', {
      method: 'POST',
      body: { level, message, meta }
    });
  } catch (e) {
    console.error('Failed to send client log', e);
  }
}