import getClosestScrollable from "./get-closest-scrollable";
// TODO: do this check at the same time as the closest scrollable
// in order to avoid double calling getComputedStyle
// Do this when we move to multiple scroll containers
const getIsFixed = (el) => {
  if (!el) {
    return false;
  }
  const style = window.getComputedStyle(el);
  if (style.position === "fixed") {
    return true;
  }
  return getIsFixed(el.parentElement);
};

const getEnv = (start) => {
  const closestScrollable = getClosestScrollable(start);
  const isFixedOnPage = getIsFixed(start);
  return {
    closestScrollable,
    isFixedOnPage
  };
};

export default getEnv;
