'use client'

import { redirect, useSearchParams } from 'next/navigation'
import { Suspense } from 'react'

import { AuthFlow } from '@/components/auth/auth-flow'
import { AuthGuard } from '@/components/auth-guard'

function RegisterContent() {
  const searchParams = useSearchParams()
  const partnerCode = searchParams.get('partner')

  return (
    <AuthGuard fallback={<AuthFlow partnerCode={partnerCode} />}>
      {/* Если пользователь авторизован, перенаправляем в дашборд */}
      {redirect('/dashboard')}
    </AuthGuard>
  )
}

export default function RegisterPage() {
  return (
    <Suspense fallback={<div>Загрузка...</div>}>
      <RegisterContent />
    </Suspense>
  )
}
