import "core-js/modules/es.array.iterator.js";
import "core-js/modules/web.dom-collections.iterator.js";
import { createContainer } from 'unstated-next';
import { useState, useRef } from 'react';
import useMergedState from 'rc-util/es/hooks/useMergedState';
function useContainer(props = {}) {
  const actionRef = useRef();
  const propsRef = useRef();

  // 共享状态比较难，就放到这里了
  const [keyWords, setKeyWords] = useState('');
  // 用于排序的数组
  const sortKeyColumns = useRef([]);
  const [tableSize, setTableSize] = useMergedState(props.size || 'large', {
    value: props.size,
    onChange: props.onSizeChange
  });
  const [columnsMap, setColumnsMap] = useMergedState(props.columnsStateMap || {}, {
    value: props.columnsStateMap,
    onChange: props.onColumnsStateChange
  });
  return {
    action: actionRef,
    setAction: newAction => {
      actionRef.current = newAction;
    },
    sortKeyColumns,
    setSortKeyColumns: keys => {
      sortKeyColumns.current = keys;
    },
    propsRef,
    columnsMap,
    keyWords,
    setKeyWords: k => setKeyWords(k),
    setTableSize,
    tableSize,
    setColumnsMap
  };
}
const Container = createContainer(useContainer);
export { useContainer };
export default Container;