import { c as defineSitemapEventHandler, u as useRuntimeConfig } from '../../../_/nitro.mjs';
import 'node:http';
import 'node:https';
import 'node:events';
import 'node:buffer';
import 'nitropack/dist/runtime/plugin';
import 'packrup';
import 'vue';
import 'consola';
import 'node:fs';
import 'node:url';
import '@iconify/utils';
import 'node:crypto';
import 'ipx';
import 'node:path';

const urls = defineSitemapEventHandler(async () => {
  const config = useRuntimeConfig();
  const baseUrl = config.public.apiBase;
  const locales = ["ar", "en"];
  const defaultLocale = "ar";
  const urls = [];
  const allProjects = [];
  let page = 1;
  let projectsRes = await $fetch(`${baseUrl}projects`, {
    params: { page }
  });
  allProjects.push(...projectsRes.data.projects.data);
  while (page < projectsRes.data.projects.last_page) {
    page++;
    projectsRes = await $fetch(`${baseUrl}projects`, {
      params: { page }
    });
    allProjects.push(...projectsRes.data.projects.data);
  }
  for (let i = 1; i <= projectsRes.data.projects.last_page; i++) {
    locales.forEach((locale) => {
      const basePath = locale === defaultLocale ? "/our-projects" : `/${locale}/our-projects`;
      urls.push({
        loc: i === 1 ? basePath : `${basePath}?page=${i}`,
        alternatives: [
          { hreflang: "x-default", href: "/our-projects" },
          ...locales.map((l) => ({
            hreflang: l,
            href: l === defaultLocale ? i === 1 ? "/our-projects" : `/our-projects?page=${i}` : i === 1 ? `/${l}/our-projects` : `/${l}/our-projects?page=${i}`
          }))
        ]
      });
    });
  }
  const allBlogs = [];
  let blogPage = 1;
  let blogsResponse = await $fetch(`${baseUrl}blogs`, {
    params: { page: blogPage }
  });
  allBlogs.push(...blogsResponse.data);
  while (blogPage < blogsResponse.meta.last_page) {
    blogPage++;
    blogsResponse = await $fetch(`${baseUrl}blogs`, {
      params: { page: blogPage }
    });
    allBlogs.push(...blogsResponse.data);
  }
  for (let i = 1; i <= blogsResponse.meta.last_page; i++) {
    locales.forEach((locale) => {
      const basePath = locale === defaultLocale ? "/blogs" : `/${locale}/blogs`;
      urls.push({
        loc: i === 1 ? basePath : `${basePath}?page=${i}`,
        alternatives: [
          { hreflang: "x-default", href: "/blogs" },
          ...locales.map((l) => ({
            hreflang: l,
            href: l === defaultLocale ? i === 1 ? "/blogs" : `/blogs?page=${i}` : i === 1 ? `/${l}/blogs` : `/${l}/blogs?page=${i}`
          }))
        ]
      });
    });
  }
  const jobsRes = await $fetch(`${baseUrl}jobs`);
  const allJobs = jobsRes.data;
  function makeUrls(slugAr, slugEn, base) {
    return locales.map((locale) => ({
      loc: locale === defaultLocale ? `/${base}/${slugAr}` : `/${locale}/${base}/${slugEn}`,
      alternatives: [
        { hreflang: "x-default", href: `/${base}/${slugAr}` },
        ...locales.map((l) => ({
          hreflang: l,
          href: l === defaultLocale ? `/${base}/${slugAr}` : `/${l}/${base}/${slugEn}`
        }))
      ]
    }));
  }
  allProjects.forEach(
    (p) => urls.push(...makeUrls(p.slug_ar, p.slug_en, "our-projects"))
  );
  allBlogs.forEach(
    (b) => urls.push(...makeUrls(b.slug_ar, b.slug_en, "blogs"))
  );
  allJobs.forEach(
    (j) => urls.push(...makeUrls(j.slug_ar, j.slug_en, "join-us"))
  );
  return urls;
});

export { urls as default };
//# sourceMappingURL=urls.mjs.map
