'use strict';

var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
var React = require('react');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var _slicedToArray__default = /*#__PURE__*/_interopDefault(_slicedToArray);

var useHasTextOverflow = function useHasTextOverflow(elementRef) {
  var text = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
  var _useState = React.useState(false),
    _useState2 = _slicedToArray__default.default(_useState, 2),
    isOverflowed = _useState2[0],
    setIsOverflowed = _useState2[1];
  React.useEffect(function () {
    var checkOverflow = function checkOverflow() {
      if (elementRef.current) {
        setIsOverflowed(elementRef.current.scrollHeight > elementRef.current.clientHeight || elementRef.current.scrollWidth > elementRef.current.clientWidth);
      }
    };
    checkOverflow();

    // Optionally add a resize listener
    var handleResize = function handleResize() {
      return checkOverflow();
    };
    window.addEventListener('resize', handleResize);
    return function () {
      window.removeEventListener('resize', handleResize);
    };
  }, [elementRef, text]);
  return isOverflowed;
};
var useHasTextOverflow$1 = useHasTextOverflow;

module.exports = useHasTextOverflow$1;
