import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import { useState, useEffect } from 'react';

function useDetectPrint() {
  var _useState = useState(false),
      _useState2 = _slicedToArray(_useState, 2),
      isPrinting = _useState2[0],
      toggleStatus = _useState2[1];

  useEffect(function () {
    var printMq = typeof window !== 'undefined' && window.matchMedia && window.matchMedia('print');

    var mqEvent = function mqEvent(mqList) {
      return toggleStatus(!!mqList.matches);
    };

    printMq.addListener(mqEvent);
    return function () {
      return printMq.removeListener(mqEvent);
    };
  });
  return isPrinting;
}

export default useDetectPrint;