"use client";

import { DiagnosticsClient } from "@bytelyst/diagnostics-client";
import { DIAGNOSTICS_URL, PRODUCT_ID } from "@/lib/product-config";

let started = false;

export function initDiagnostics() {
  if (started) {
    return DiagnosticsClient.getInstance();
  }

  const client = DiagnosticsClient.getInstance({
    productId: PRODUCT_ID,
    anonymousInstallId: `${PRODUCT_ID}-web-install`,
    platform: "web",
    channel: "notes_web",
    osFamily: "macos",
    appVersion: "0.1.0",
    buildNumber: "1",
    releaseChannel: "dev",
    serverUrl: DIAGNOSTICS_URL,
    pollIntervalMs: 30000,
    captureConsole: false,
    captureErrors: true,
    captureNetwork: false,
  });

  client.start().catch(() => {
    // Diagnostics is best-effort during scaffold phase.
  });
  started = true;
  return client;
}
