import { NextRequest, NextResponse } from "next/server";

const BACKEND =
  process.env.MEDUSA_BACKEND_URL ||
  process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL ||
  "https://ot.azulado.cloud";

export async function POST(req: NextRequest) {
  const body = (await req.json().catch(() => ({}))) as { path?: string };
  const path = String(body.path || "/");
  if (path.startsWith("/ops") || path.startsWith("/negocio") || path.startsWith("/api")) {
    return NextResponse.json({ ok: true });
  }
  await fetch(`${BACKEND}/hooks/ot-ops/visits`, {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ path }),
  }).catch(() => undefined);
  return NextResponse.json({ ok: true });
}
