import { useLocation, useMatch, useNavigate, useParams } from 'react-router-dom'

const useHistory = () => {
  const navigate = useNavigate()
  const { pathname, search } = useLocation()

  return {
    push: navigate,
    location: {
      pathname: pathname,
      search: search,
    },
  }
}
const useRouteMatch = (path?) => {
  const { pathname } = useLocation()
  const params = useParams()
  const match = useMatch({ path, end: false })
  // console.log({
  //   match,
  //   params,
  //   pathname,
  // })
  return {
    params: params,
    path: match?.pattern?.path,
    url: pathname,
  }
}

export { useHistory, useRouteMatch }
