import { createContext, useContext } from 'react';

export const getScrollOffsetToChild = (input) => {
  let totalOffset = 0;
  let currentElement = input;

  while (currentElement && currentElement?.tagName !== 'FORM') {
    totalOffset += currentElement.offsetTop;
    currentElement = currentElement.offsetParent;
  }

  return totalOffset;
};

export const FormContext = createContext({
  size: 'small',
});
export const SubFormGroupContext = createContext(0);

export const useFormSettings = () => useContext(FormContext);
export const useFormGroupSettings = () => useContext(SubFormGroupContext);
