import { UAParser } from 'ua-parser-js';

export const ua = () => UAParser(window.navigator.userAgent);

// ua-parser-js reports macOS as 'macOS' (v2+); older versions used 'Mac OS'.
// Accept both so the ⌘-vs-Ctrl shortcut hints render correctly on real Macs.
export const isMacOS = () => {
  const name = ua().os.name;
  return name === 'macOS' || name === 'Mac OS';
};

export const mobileOrTablet = (): boolean => {
  const userAgent = ua();
  const { os, device } = userAgent;
  if (device.type === 'mobile' || device.type === 'tablet') return true;
  if (os.name === 'Android' || os.name === 'iOS') return true;
  return false;
};
