const checkRestTime = (sessionItem:string, validTime:number = 60) => {
  let LASTTIME:number, restTime:number

  const hasRecord = sessionStorage.getItem(sessionItem)
  const nowTime = Math.round(new Date().getTime() / 1000)
  if (hasRecord) {
    LASTTIME = Math.round(Number(hasRecord))
  } else {
    return null
  }

  if (LASTTIME && nowTime - LASTTIME < validTime) {
    restTime = validTime - (nowTime - LASTTIME)
    return restTime
  } else if (LASTTIME && nowTime - LASTTIME >= 60) {
    sessionStorage.removeItem(sessionItem)
    return null
  }
}
export default checkRestTime
