import { redirect } from "next/navigation";
import { cookies, headers } from "next/headers";

export default async function RootPage() {
  const headersList = await headers();
  const cookieStore = await cookies();
  const acceptLanguage = headersList.get("accept-language") || "";
  const cookieLocale = cookieStore.get("NEXT_LOCALE")?.value;

  let locale = "sr";
  if (cookieLocale && ["sr", "en", "de", "fr"].includes(cookieLocale)) {
    locale = cookieLocale;
  } else if (acceptLanguage.includes("en")) {
    locale = "en";
  }

  redirect(`/${locale}`);
}
