import { setPreviewData } from "@/lib/previewContext"

import InitLivePreview from "@/components/LivePreview"

import type { PageArgs, UIDParams } from "@/types/params"

export default async function PreviewPage(
  props: PageArgs<UIDParams, URLSearchParams>
) {
  const params = await props.params
  const searchParams = await props.searchParams
  const shouldInitializePreview = searchParams.isPreview === "true"

  if (searchParams.live_preview) {
    setPreviewData({ hash: searchParams.live_preview, uid: params.uid })
  }

  return shouldInitializePreview ? <InitLivePreview /> : null
}
