import { PaymentCallbackPage as PaymentCallbackPagePrimitive } from "@scandic-hotels/booking-flow/pages/PaymentCallbackPage"
import { logger } from "@scandic-hotels/common/logger"

import { bookingFlowConfig } from "@/constants/bookingFlowConfig"

import { getSocialSession, isValidSocialSession } from "@/auth/scandic/session"

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

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

export default async function PaymentCallbackPage(
  props: PageArgs<LangParams & { status: string }>
) {
  const searchParams = await props.searchParams
  const params = await props.params
  logger.debug(`[payment-callback] callback started`)
  const lang = params.lang

  let userAccessToken = null
  const session = await getSocialSession()
  if (isValidSocialSession(session)) {
    userAccessToken = session.access_token
  }

  return (
    <PaymentCallbackPagePrimitive
      lang={lang}
      userAccessToken={userAccessToken}
      searchParams={searchParams}
      status={params.status as PaymentCallbackStatusEnum}
      config={bookingFlowConfig}
    />
  )
}
