import { EmailTemplate } from "@/components/custom/ContactSender";
import { supabase } from "@/lib/supabase";

export async function POST(request) {
  try {
    const formData = await request.json();

    // Store form data in Supabase
    const { data: supabaseData, error: supabaseError } = await supabase
      .from("rankrunners-submission")
      .insert([
        {
          name: formData.name,
          email: formData.emailAddress,
          phone: formData.phoneNumber,
          subject: formData.subject,
          message: formData.message,
        },
      ])
      .select();

    if (supabaseError) {
      console.log("err", supabaseError);
      return Response.json({ error: supabaseError }, { status: 500 });
    }

    return Response.json({
      supabaseData,
      message: "Form submitted successfully",
    });
  } catch (error) {
    console.log("Error:", error);
    return Response.json({ error: error.message }, { status: 500 });
  }
}
