import { Navigate, Outlet } from 'react-router-dom'
import React from 'react'

interface PrivateRouteProps {
  isAllowed: boolean
  redirectPath?: string
  children?: React.ReactNode
}

const PrivateRoute = ({
  isAllowed,
  redirectPath = '/login',
  children
}: PrivateRouteProps) => {
  if (!isAllowed) {
    return <Navigate to={redirectPath} replace />
  }

  return children ? children : <Outlet />
}

export default PrivateRoute