import type { GlobalAfterChangeHook } from 'payload'

import { revalidateTag } from 'next/cache'

export const revalidateHome: GlobalAfterChangeHook = async ({ doc, req }) => {
  const { payload, context } = req
  if (!context.disableRevalidate) {
    payload.logger.info(`Revalidating home`)

    revalidateTag('global_home')
  }

  return doc
}
