import type { LandingPageContent } from '@/components/landing/content';
import { unstable_noStore as noStore } from 'next/cache';
import { mergeLandingPageContent } from '@/components/landing/content';

import { getPayloadClient } from './get-payload';

export const getLandingPageContent = async (
  isPreview = false,
): Promise<LandingPageContent> => {
  if (isPreview) {
    noStore();
  }

  const payload = await getPayloadClient();
  const landingPage = await payload.findGlobal({
    slug: 'landing-page',
    draft: isPreview,
  });

  return mergeLandingPageContent(landingPage);
};
