import { h } from '@stencil/core';
import { isNonNullable } from '../../../types/type-guard';
export const VegaTableScrollableContainer = ({ scrollConfig = {}, ref, onScroll }, children) => {
  const { maxHeight } = scrollConfig;
  const isVerticalScrollable = isNonNullable(maxHeight);
  const handleVerticalScroll = (e) => {
    if (!isVerticalScrollable)
      return;
    const target = e.target;
    if (target.scrollTop === 0) {
      target.classList.remove('scrolled');
      return;
    }
    if (target.scrollTop > 0 && !target.classList.contains('scrolled')) {
      target.classList.add('scrolled');
    }
    onScroll(e);
  };
  return (h("div", { class: "vega-table-scrollable-container", style: {
      maxHeight: typeof maxHeight === 'number' ? `${maxHeight}px` : maxHeight,
    }, ref: ref, 
    /* eslint-disable-next-line react/jsx-no-bind */
    onScroll: handleVerticalScroll }, children));
};
