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

import InitLivePreview from "@/components/LivePreview"

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

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

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

  return shouldInitializePreview ? <InitLivePreview /> : null
}
