import { getServerSideSitemap } from 'next-sitemap'
import { GetServerSideProps } from 'next'
import { fetchAdsEndpoints } from 'apiCalls/apiEndpoints'

export const getServerSideProps: GetServerSideProps = async (ctx) => {
  // Method to source urls from cms
  // const urls = await fetch('https//example.com/api')

  //ads
  const urls = await fetchAdsEndpoints()

  console.log('urls', urls.data)
  const transformed_objs = urls.data?.map((item: any) => {
    return {
      loc: item,
      lastmod: new Date().toISOString(),
      changefreq: 'daily'
    }
  })

  const fields = transformed_objs;

  // {
  //   loc: 'https://uiv2.ashantiweb.com', // Absolute url
  //   lastmod: new Date().toISOString(),
  // changefreq
  //   // priority
  // },
  // {
  //   loc: 'https://uiv2.ashantiweb.com/dynamic-path-2', // Absolute url
  //   lastmod: new Date().toISOString(),
  //   // changefreq
  //   // priority
  // },

  return getServerSideSitemap(ctx, fields)
}

// Default export to prevent next.js errors
export default function Sitemap() { }