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-schedules")
      .insert([
        {
          first_name: formData.firstName,
          last_name: formData.lastName,
          email: formData.emailAddress,
          phone: formData.phoneNumber,
          company_name: formData.companyName,
          web_url: formData.websiteUrl,
          revenue: formData.annualRevenue,
          learn_option: formData.learnFrom,
          additional_info: formData.additionalInfo,
        },
      ])
      .select();

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

    return Response.json({
      supabaseData,
      message: "Appointment Scheduled Successfully!",
    });
  } catch (error) {
    console.log("Error:", error);
    return Response.json({ error: error.message }, { status: 500 });
  }
}
