import { useMemo } from 'react';
import { useFetchConfig, useUpdateConfig } from './useConfigApi.js';
import { mergeConfig, packConfig } from './utils.js';
import '@tanstack/react-query';
import '../useMutationWithInvalidation/useMutationWithInvalidation.js';
import '../../defineProperty-CrCYjjU3.js';
import '../../typeof-D-UKOauR.js';
import '../../objectWithoutProperties-DN7d1SzH.js';
import 'ramda';
import './api.js';
import 'axios';
import './constants.js';

var useColumnConfig = function useColumnConfig(_ref) {
  var tableKey = _ref.tableKey,
    defaultColumnData = _ref.defaultColumnData;
  var _useFetchConfig = useFetchConfig({
      tableKey: tableKey
    }),
    isLoading = _useFetchConfig.isLoading,
    configData = _useFetchConfig.data;
  var _useUpdateConfig = useUpdateConfig({
      tableKey: tableKey
    }),
    updateConfig = _useUpdateConfig.mutate;
  var configuration = configData === null || configData === void 0 ? void 0 : configData.columns;
  var columnData = useMemo(function () {
    return mergeConfig(defaultColumnData, configuration);
  }, [defaultColumnData, configuration]);
  var onUpdateColumns = function onUpdateColumns(columnsOrCallback) {
    var columns = typeof columnsOrCallback === "function" ? columnsOrCallback(columnData) : columnsOrCallback;
    var payload = {
      tableKey: tableKey,
      columns: packConfig(columns)
    };
    updateConfig({
      tableKey: tableKey,
      payload: payload
    });
  };
  return {
    isLoading: isLoading,
    columnData: columnData,
    onUpdateColumns: onUpdateColumns
  };
};

export { useColumnConfig as default };
//# sourceMappingURL=useColumnConfig.js.map
