import { useCallback, useEffect, useState, useRef } from "react";
var noop = function noop() {};
var emptyArray = [];
export default (function (defaultColumnOrder, onChange) {
  if (defaultColumnOrder === void 0) {
    defaultColumnOrder = emptyArray;
  }
  if (onChange === void 0) {
    onChange = noop;
  }
  var _useState = useState(function () {
      return defaultColumnOrder;
    }),
    columnOrder = _useState[0],
    setColumnOrder = _useState[1];
  var initialSetRef = useRef(false);
  useEffect(function () {
    if (!defaultColumnOrder || columnOrder === defaultColumnOrder) return;
    initialSetRef.current = true;
    setColumnOrder(defaultColumnOrder);
  }, [defaultColumnOrder]);
  var onColumnOrderChange = useCallback(function (value) {
    var newOrder = typeof value === "function" ? value(columnOrder) : value;
    onChange(newOrder);
    setColumnOrder(newOrder);
  }, [columnOrder, onChange]);
  return [columnOrder, onColumnOrderChange];
});