import { useCallback, useEffect, useState } 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];
  useEffect(function () {
    if (columnVisibility === defaultColumnVisibility) return;
    setColumnVisibility(defaultColumnVisibility);
  }, [defaultColumnVisibility]);
  var onVisibilityChange = useCallback(function (getValue) {
    var newValue = getValue(columnVisibility);
    onChange(newValue);
    setColumnVisibility(newValue);
  }, [columnVisibility]);
  return [columnVisibility, onVisibilityChange];
});