import { Navigate } from 'react-router-dom'
import useStore from '../store.js'

export function ProtectedRoute({ children }) {
  const { isAuthenticated } = useStore()
  if (!isAuthenticated) {
    return <Navigate to="/login" replace />
  }
  return children
}

export function AdminRoute({ children }) {
  const { isAuthenticated, authRole } = useStore()
  if (!isAuthenticated) {
    return <Navigate to="/login" replace />
  }
  if (authRole !== 'admin') {
    return <Navigate to="/client/dashboard" replace />
  }
  return children
}

export function ClientRoute({ children }) {
  const { isAuthenticated, authRole } = useStore()
  if (!isAuthenticated) {
    return <Navigate to="/login" replace />
  }
  if (authRole !== 'client') {
    return <Navigate to="/admin/dashboard" replace />
  }
  return children
}