import { notFound } from "next/navigation"

import { logger } from "@scandic-hotels/common/logger"

import { myStay } from "@/constants/routes/webviews"

import GuaranteeCallbackPage from "@/components/GuaranteeCallback"

import type { PaymentCallbackStatusEnum } from "@scandic-hotels/common/constants/paymentCallbackStatusEnum"

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

export default async function GuaranteePaymentWebViewCallbackPage(
  props: PageArgs<
    LangParams,
    {
      status?: PaymentCallbackStatusEnum
      RefId?: string
      confirmationNumber?: string
      ancillary?: string
    }
  >
) {
  const searchParams = await props.searchParams
  const params = await props.params
  logger.debug(`[gla-payment-callback] callback started`)
  const lang = params.lang
  const status = searchParams.status
  const confirmationNumber = searchParams.confirmationNumber
  const refId = searchParams.RefId
  if (!status || !confirmationNumber || !refId) {
    notFound()
  }
  const myStayUrl = `${myStay[lang]}?RefId=${encodeURIComponent(refId)}`

  return (
    <GuaranteeCallbackPage
      status={status}
      confirmationNumber={confirmationNumber}
      refId={refId}
      myStayUrl={myStayUrl}
      lang={lang}
      isAncillaryFlow={!!searchParams.ancillary}
    />
  )
}
