import { API_BASE_URL } from "../config/api";
import { getAccessToken } from "../utils/auth";

export const sendPageLog = async (pageTitle: string): Promise<void> => {
  const token = getAccessToken();
  if (!token) return;

  // Fire and forget - no need to wait for response
  fetch(`${API_BASE_URL}/api/call`, {
    method: "POST",
    headers: {
      "Content-Type": "application/json;charset=UTF-8",
      "Authorization": `Bearer ${token}`,
    },
    body: JSON.stringify({
      user_log_function: {
        page_title: pageTitle,
      },
    }),
  }).catch((error) => {
    // Silent fail - logging should not interrupt user experience
    console.debug("Page log failed:", error);
  });
};
