import { NextResponse } from "next/server";

export async function GET(req: Request) {
  try {
    const { searchParams } = new URL(req.url);
    const location = searchParams.get("location") || "lahore"; 
    const page = searchParams.get("page") || "1";

    const response = await fetch(
      `https://crm-universitiespage.com/reactapis/api/crm_employees?location=${location}`, 
      {
        headers: {
          Authorization: `Bearer ${process.env.CRM_API_KEY}`,
        },
      }
    );

    if (!response.ok) {
      return NextResponse.json({ success: false, message: "Failed to fetch employees" }, { status: 500 });
    }

    const data = await response.json();
    return NextResponse.json(data);
  } catch (error) {
    return NextResponse.json({ success: false, message: "Server Error" }, { status: 500 });
  }
}

