import { env } from "@/env/server"
import { getProfile } from "@/lib/trpc/memoizedRequests"
import { serverClient } from "@/lib/trpc/server"

import SurprisesClient from "./Client"

export default async function Surprises() {
  if (env.HIDE_FOR_NEXT_RELEASE) {
    return null
  }

  const user = await getProfile()

  if (!user || "error" in user) {
    return null
  }

  const surprises = await serverClient().contentstack.rewards.surprises()

  if (!surprises) {
    return null
  }

  return (
    <SurprisesClient
      surprises={surprises}
      membershipNumber={user.membership?.membershipNumber}
    />
  )
}
