import { useHistory } from 'react-router-dom'

import { PAGES } from 'config'
import { removeToken } from 'helpers'
// import { logout } from 'requests'

// временная заглушка запроса
const logout = () => Promise.resolve()

type Args = {
  setToken: (token: string | null) => void,
}

export const useLogout = ({ setToken }: Args) => {
  const history = useHistory()

  const onSuccess = () => {
    removeToken()
    setToken(null)
    history.replace(PAGES.login)
  }

  return async () => (
    logout().then(onSuccess)
  )
}
