import { useRequestHeaders } from '#app'

export function useClientDevice() {
  const isMobileDevice = () => {
    let userAgent = navigator ? navigator.userAgent : null

    if (userAgent === null) {
      const headers = useRequestHeaders()
      console.error(headers)
      userAgent = headers['user-agent']
    }

    if (!userAgent) {
      return false
    }

    return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
      userAgent
    )
  }

  return {
    isMobileDevice,
  }
}
