import GalleryPage, { GalleryPageProps } from 'components/GalleryPage'
import { usePreview } from 'lib/sanity.preview'
import { type Gallery, postAndMoreGallleriesQuery } from 'lib/sanity.queries'

export default function PreviewGalleryPage({
  token,
  post,
  settings,
}: {
  token: null | string
} & GalleryPageProps) {
  const {
    post: postPreview,
    morePosts,
  }: { post: Gallery; morePosts: Gallery[] } = usePreview(
    token,
    postAndMoreGallleriesQuery,
    {
      slug: post.slug,
    }
  ) || { post: null, morePosts: [] }

  return (
    <GalleryPage
      preview
      post={postPreview}
      morePosts={morePosts}
      settings={settings}
    />
  )
}
