import { MonitorReportData } from '.'

const startTime = Date.now()

export function getLiveTime() {
  if (window.performance.now) {
    return Math.floor(window.performance.now())
  } else {
    const nowTime = Date.now() - 0
    return Math.floor(startTime - nowTime)
  }
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function handleRouteConfig({ matched, ...rest }) {
  return rest
}

interface LocalLogData extends MonitorReportData {
  t: number
}
const local = JSON.parse(localStorage.getItem('monitor') || '[]') as LocalLogData[]
export const localLog = (data: MonitorReportData) => {
  ;(data as LocalLogData).t = Date.now()
  local.push(data as LocalLogData)
  localStorage.setItem('monitor', JSON.stringify(local))
}
