"use strict";

exports.__esModule = true;
exports["default"] = void 0;
var _react = require("react");
var initialScrollWidth = -1;
var initialClientWidth = -1;
var _default = exports["default"] = function _default(parentRef, ref, target, callback, deps) {
  var prevScrollWidthRef = (0, _react.useRef)(initialScrollWidth);
  var prevClientWidthRef = (0, _react.useRef)(initialClientWidth);
  return (0, _react.useCallback)(function () {
    if (!ref.current || !target.current || !parentRef || !parentRef.current) return;
    var width = document.body.clientWidth;
    var draggableTabs = ref.current;
    var draggableLeft = draggableTabs.getBoundingClientRect().left;
    var container = parentRef.current;
    var _container$getBoundin = container.getBoundingClientRect(),
      containerRight = _container$getBoundin.right,
      containerLeft = _container$getBoundin.left;
    var _target$current$getBo = target.current.getBoundingClientRect(),
      tabRight = _target$current$getBo.right,
      tabWidth = _target$current$getBo.width;
    if (prevScrollWidthRef.current === draggableTabs.scrollWidth && prevClientWidthRef.current === width) return;
    prevScrollWidthRef.current = draggableTabs.scrollWidth;
    prevClientWidthRef.current = width;
    var padRight = width - containerRight;
    if (tabRight < width - padRight && containerLeft + (draggableLeft - containerLeft) + (tabRight - draggableLeft) + padRight > width) return;
    if (tabRight >= containerRight) return callback(true);
    if (tabRight + tabWidth < containerRight) return callback(false);
  }, deps);
};