import type Page from "~~/types/collection/page";
import type Global from "~~/types/single/global";

export default defineNuxtPlugin(async (nuxtApp) => {
  const pageState = useState<Page[]>("sitemap_pages", () => []);

  if (pageState.value.length == 0) {
    const { find } = useStrapi();
    const { data: page_res } = await useAsyncData(
      "sitemap_pages",
      () =>
        find<Page>("pages", {
          filters: {
            //@ts-ignore
            $or: [
              {
                ref_only_access: { $eq: false },
              },
              {
                ref_only_access: { $null: true },
              },
            ],
          },
        }),
      {
        server: true,
        lazy: false,
        default: () => {},
      }
    );
    pageState.value = page_res.value?.data ?? [];
  }
});
