import { NextResponse } from "next/server";

export async function POST(req: Request) {
  try {
    const body = (await req.json()) as {
      name?: string;
      email?: string;
      message?: string;
      lang?: string;
    };

    const name = (body.name ?? "").trim();
    const email = (body.email ?? "").trim();
    const message = (body.message ?? "").trim();

    if (name.length < 2 || !email.includes("@") || message.length < 10) {
      return NextResponse.json(
        { ok: false, error: "invalid_payload" },
        { status: 400 },
      );
    }

    // i18n-ready + API-ready endpoint:
    // - On Vercel: connect to an email provider (Resend/SendGrid) or CRM API.
    // - On cPanel: forward to a server-side SMTP endpoint.
    // For now, we acknowledge receipt so the UX is complete.
    return NextResponse.json({ ok: true });
  } catch {
    return NextResponse.json({ ok: false, error: "bad_request" }, { status: 400 });
  }
}

