import LinkButton from '@/components/LinkButton'
import type { ReactNode } from 'react'
import { useLocation } from 'react-router-dom'
import type { BackLoc } from '../InstructorView/useLeftNavbar'

const useAdaptiveBack = (element: ReactNode) => {
  const loc = useLocation()
  const backLoc = (loc.state as BackLoc)?.backloc

  return (
    <div>
      {backLoc && <LinkButton {...backLoc} />}
      {element}
    </div>
  )
}

export default useAdaptiveBack
