/* eslint-disable @typescript-eslint/naming-convention */
import { useEffect, useState } from 'react';
import { inBrowser } from '../utils';
import useEventListener from './use-event-listener';

function usePageVisibility() {
  var _useState = useState('visible'),
      visibility = _useState[0],
      _setVisibility = _useState[1];

  var setVisibility = function setVisibility() {
    if (inBrowser) {
      _setVisibility(document.hidden ? 'hidden' : 'visible');
    }
  };

  useEffect(function () {
    setVisibility();
  }, []);
  useEventListener('visibilitychange', setVisibility, {
    depends: [visibility]
  });
  return visibility;
}

export default usePageVisibility;