import { redirect } from "next/navigation";

import { loadFunnelPaymentById } from "@/entities/session/funnel/loaders";
import { ROUTES } from "@/shared/constants/client-routes";
import { ELocalesPlacement } from "@/types";

const payload = {
  funnel: ELocalesPlacement.CompatibilityV2,
};

export default async function AdditionalPurchasesPage() {
  const pages = await loadFunnelPaymentById(payload, "additionalProducts");

  if (!pages || !Array.isArray(pages) || pages.length === 0) {
    return redirect(ROUTES.home());
  }

  return redirect(ROUTES.additionalPurchases(pages[0].type));
}
