import { useCallback, useEffect, useState, useRef } from "react";
var noop = function noop() {};
var emptyObj = {};
export default (function (defaultColumnVisibility, onChange) {
  if (defaultColumnVisibility === void 0) {
    defaultColumnVisibility = emptyObj;
  }
  if (onChange === void 0) {
    onChange = noop;
  }
  var _useState = useState(function () {
      return defaultColumnVisibility;
    }),
    columnVisibility = _useState[0],
    setColumnVisibility = _useState[1];
  var initialSetRef = useRef(false);
  useEffect(function () {
    if (columnVisibility === defaultColumnVisibility) return;
    initialSetRef.current = true;
    setColumnVisibility(defaultColumnVisibility);
  }, [defaultColumnVisibility]);
  var onVisibilityChange = useCallback(function (getValue) {
    onChange(getValue(columnVisibility));
    setColumnVisibility(getValue(columnVisibility));
  }, [columnVisibility]);
  return [columnVisibility, onVisibilityChange];
});