function getVisibilityOptions() {
  let hidden;
  let visibilityChangeEvent;
  if ('hidden' in document) {
    hidden = 'hidden';
    visibilityChangeEvent = 'visibilitychange';
  }
  else if ('msHidden' in document) {
    hidden = 'msHidden';
    visibilityChangeEvent = 'msvisibilitychange';
  }
  else if ('webkitHidden' in document) {
    hidden = 'webkitHidden';
    visibilityChangeEvent = 'webkitvisibilitychange';
  }
  return { hidden, visibilityChangeEvent };
}
/**
 * passes the visiblity of the page to the given method
 */
function handleVisibilityChange(method, documentHiddenProperty) {
  method.apply(this, [!document[documentHiddenProperty]]);
}
/**
 * method decorator that will be called whenever the page visiblity changes, using the PageVisibility API
 */
export default function PageVisibilityChange() {
  return (proto, method) => {
    const { connectedCallback, disconnectedCallback } = proto;
    const visiblityOptions = getVisibilityOptions();
    if (typeof visiblityOptions.hidden === 'undefined') {
      console.warn('This browser does not support Page Visibility API.');
      return;
    }
    /**
     * when the component is initialized, start tracking the page visibility
     */
    proto.connectedCallback = function () {
      document.addEventListener(visiblityOptions.visibilityChangeEvent, handleVisibilityChange.bind(this, proto[method], visiblityOptions.hidden), false);
      return connectedCallback && connectedCallback.apply(this);
    };
    /**
     * when the component is destroyed, stop tracking page visibility
     */
    proto.disconnectedCallback = function () {
      document.removeEventListener(visiblityOptions.visibilityChangeEvent, handleVisibilityChange.bind(this, proto[method], visiblityOptions.hidden), false);
      return disconnectedCallback && disconnectedCallback.apply(this);
    };
  };
}
//# sourceMappingURL=page-visibility.js.map
