'use strict';

var React = require('react');
var v2_reactUtils_useColumnConfig_useConfigApi = require('./useConfigApi.js');
var v2_reactUtils_useColumnConfig_utils = require('./utils.js');
require('@tanstack/react-query');
require('../useMutationWithInvalidation/useMutationWithInvalidation.js');
require('../../../defineProperty-COGyJ6Og.js');
require('../../../toPropertyKey-DW-YC76_.js');
require('../../../typeof-D4ZZ_FlZ.js');
require('../../../objectWithoutProperties-wSsbHFcG.js');
require('ramda');
require('./api.js');
require('axios');
require('./constants.js');

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

module.exports = useColumnConfig;
//# sourceMappingURL=useColumnConfig.js.map
