// import GlaAccreditationBody from "@/components/Gla/GlaAccreditationBody";
// import GlaMain from "@/components/Gla/GlaMain";
// import GlaPurpose from "@/components/Gla/GlaPurpose";
// import GlaPurpose2 from "@/components/Gla/GlaPurpose2";
// import { BASE_URL } from "@/Constant";

// async function getData() {
//   try {
//     const [res, res1, res2, res3, res4, res5, res6] = await Promise.allSettled([
//       fetch(`${BASE_URL}iaabGlaPageData`, {
//         cache: "no-store",
//       }),
//       fetch(`${BASE_URL}iaabGlaPageData/purpose`, {
//         cache: "no-store",
//       }),
//       fetch(`${BASE_URL}iaabGlaPageData/scope`, {
//         cache: "no-store",
//       }),
//       fetch(`${BASE_URL}iaabGlaPageData/evalution`, {
//         cache: "no-store",
//       }),
//       fetch(`${BASE_URL}iaabGlaPageData/evalution-process`, {
//         cache: "no-store",
//       }),
//       fetch(`${BASE_URL}iaabGlaPageData/download`, {
//         cache: "no-store",
//       }),
//       fetch(`${BASE_URL}iaabGlaPageData/table`, {
//         cache: "no-store",
//       }),
//     ]);

//     const resUp =
//       res.status === "fulfilled" && res.value.ok
//         ? await res.value.json()
//         : null;

//         const resTable =
//       res6.status === "fulfilled" && res6.value.ok
//         ? await res6.value.json()
//         : null;

//     const resPurpose =
//       res1.status === "fulfilled" && res1.value.ok
//         ? await res1.value.json()
//         : null;
        
//     const resScope =
//       res2.status === "fulfilled" && res2.value.ok
//         ? await res2.value.json()
//         : null;
//     const resEvalution =
//       res3.status === "fulfilled" && res3.value.ok
//         ? await res3.value.json()
//         : null;
//     const resEvalutionProcess =
//       res4.status === "fulfilled" && res4.value.ok
//         ? await res4.value.json()
//         : null;
//     const resDownload =
//       res5.status === "fulfilled" && res5.value.ok
//         ? await res5.value.json()
//         : null;

//     return {
//       resUp: resUp?.data || [],
//       resPurpose: resPurpose?.data?.iaabs[0],
//       resScope: resScope?.data?.iaabs[0],
//       resEvalution: resEvalution?.data?.iaabs[0],
//       resEvalutionProcess: resEvalutionProcess?.data?.data[0],
//       resDownload: resDownload?.data?.data[0],
//       resTable: resTable?.data?.postCategory,
//     };
//   } catch (error) {
//     console.error("Error fetching data:", error);
//     return {
//       resUp: [],
//       resPurpose: {},
//       resScope: {},
//       resEvalution: {},
//       resEvalutionProcess: {},
//       resDownload: {},
//       resTable:{}
//     };
//   }
// }

// export default async function GlaPage() {
//   const res = await getData();
//   return (
//     <div className="bg-hero bg-cover pt-5 px-4">
//       <GlaAccreditationBody main={res?.resUp} />
//       <GlaPurpose data={res?.resPurpose} />
//       <GlaMain data={res?.resScope} />
//       <GlaPurpose2
//         data={res?.resEvalution}
//         evalution={res?.resEvalutionProcess}
//         download={res?.resDownload}
//         table={res?.resTable}
//       />
//     </div>
//   );
// }


// ✅ Enable dynamic rendering for this page
export const dynamic = "force-dynamic";

import GlaAccreditationBody from "@/components/Gla/GlaAccreditationBody";
import GlaMain from "@/components/Gla/GlaMain";
import GlaPurpose from "@/components/Gla/GlaPurpose";
import GlaPurpose2 from "@/components/Gla/GlaPurpose2";
import { BASE_URL } from "@/Constant";

async function getData() {
  try {
    const [res, res1, res2, res3, res4, res5, res6] = await Promise.allSettled([
      fetch(`${BASE_URL}iaabGlaPageData`, { cache: "no-store" }),
      fetch(`${BASE_URL}iaabGlaPageData/purpose`, { cache: "no-store" }),
      fetch(`${BASE_URL}iaabGlaPageData/scope`, { cache: "no-store" }),
      fetch(`${BASE_URL}iaabGlaPageData/evalution`, { cache: "no-store" }),
      fetch(`${BASE_URL}iaabGlaPageData/evalution-process`, { cache: "no-store" }),
      fetch(`${BASE_URL}iaabGlaPageData/download`, { cache: "no-store" }),
      fetch(`${BASE_URL}iaabGlaPageData/table`, { cache: "no-store" }),
    ]);

    const resUp =
      res.status === "fulfilled" && res.value.ok
        ? await res.value.json()
        : null;

    const resPurpose =
      res1.status === "fulfilled" && res1.value.ok
        ? await res1.value.json()
        : null;

    const resScope =
      res2.status === "fulfilled" && res2.value.ok
        ? await res2.value.json()
        : null;

    const resEvalution =
      res3.status === "fulfilled" && res3.value.ok
        ? await res3.value.json()
        : null;

    const resEvalutionProcess =
      res4.status === "fulfilled" && res4.value.ok
        ? await res4.value.json()
        : null;

    const resDownload =
      res5.status === "fulfilled" && res5.value.ok
        ? await res5.value.json()
        : null;

    const resTable =
      res6.status === "fulfilled" && res6.value.ok
        ? await res6.value.json()
        : null;

    return {
      resUp: resUp?.data || [],
      resPurpose: resPurpose?.data?.iaabs?.[0] || {},
      resScope: resScope?.data?.iaabs?.[0] || {},
      resEvalution: resEvalution?.data?.iaabs?.[0] || {},
      resEvalutionProcess: resEvalutionProcess?.data?.data?.[0] || {},
      resDownload: resDownload?.data?.data?.[0] || {},
      resTable: resTable?.data?.postCategory || [],
    };
  } catch (error) {
    console.error("Error fetching data:", error);
    return {
      resUp: [],
      resPurpose: {},
      resScope: {},
      resEvalution: {},
      resEvalutionProcess: {},
      resDownload: {},
      resTable: [],
    };
  }
}

export default async function GlaPage() {
  const res = await getData();
  return (
    <div className="bg-hero bg-cover pt-5 px-4">
      <GlaAccreditationBody main={res?.resUp} />
      <GlaPurpose data={res?.resPurpose} />
      <GlaMain data={res?.resScope} />
      <GlaPurpose2
        data={res?.resEvalution}
        evalution={res?.resEvalutionProcess}
        download={res?.resDownload}
        table={res?.resTable}
      />
    </div>
  );
}
