import { useEffect } from 'react'
import { useNavigate } from 'react-router-dom'
import { RoleSelector } from './RoleSelector'
import { useClassroomLogic } from '@/utils/hooks/useClassroomLogic'
import { ROUTES_ENUM } from '@/routes/route.constant'
import { Room } from './Room'

export function Dashboard() {
  const { roleState, currentClass, handleRoleSelect, handleLeaveClass } = useClassroomLogic()
  const navigate = useNavigate()

  // Eğer dashboard seçildiyse otomatik yönlendirme yap
  useEffect(() => {
    if (roleState === 'dashboard') {
      navigate(ROUTES_ENUM.protected.admin.classroom.classes, { replace: true })
    }
  }, [roleState, navigate])

  // Render edilecek içerik
  const renderContent = () => {
    switch (roleState) {
      case 'role-selection':
        return <RoleSelector onRoleSelect={handleRoleSelect} />

      case 'classroom':
        return currentClass ? (
          <Room classSession={currentClass} onLeaveClass={handleLeaveClass} />
        ) : null

      default:
        return null
    }
  }

  return renderContent()
}
