"use strict";

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