import type { BlogTelemetry } from "@blog";
import { logClientEvent, type EventData } from "@/lib/axiom/client";

// Server module is lazy-imported so this file is safe to pull into the client
// bundle (blogConfig is imported by client components like blog-list.tsx).
// Static `import` of @/lib/axiom/server would drag @axiomhq/nextjs's
// AsyncLocalStorage init into the browser and crash at module evaluation.
export const blogTelemetry: BlogTelemetry = {
  logClientEvent: (name, data) => logClientEvent(name, data as EventData),
  logServerEvent: async (name, data) => {
    const { logEvent, logger } = await import("@/lib/axiom/server");
    logEvent(name, data as EventData);
    await logger.flush();
  },
};
