import { NextResponse } from "next/server";
import { joomlaService } from "@/services/joomlaService";
import { NavigationResponse } from "@/types/navigation";

export async function getNavigationData(): Promise<NavigationResponse> {
  return await joomlaService.getNavigation();
}

export async function GET() {
  try {
    const data = await getNavigationData();
    return NextResponse.json(data, {
      status: 200,
      headers: {
        "Cache-Control": "public, s-maxage=60, stale-while-revalidate=300",
      },
    });
  } catch (error) {
    console.error("Failed to fetch navigation data:", error);
    return NextResponse.json(
      { error: "Internal Server Error fetching navigation data" },
      { status: 500 }
    );
  }
}
