var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/dataSourceComponents/dataSourceTable/BaseTable.tsx
var BaseTable_exports = {};
__export(BaseTable_exports, {
  default: () => BaseTable_default
});
module.exports = __toCommonJS(BaseTable_exports);
var import_react = __toESM(require("react"));
var import_ahooks = require("ahooks");
var import_table = __toESM(require("../../table"));
var import_useVariables = __toESM(require("../hooks/useVariables"));
var import_ActionsProvider = __toESM(require("../provider/actions/ActionsProvider"));
var import_useDrawerState = __toESM(require("./hooks/useDrawerState"));
var import_useDesignMode = __toESM(require("./hooks/useDesignMode"));
var import_useComponentId = __toESM(require("../hooks/useComponentId"));
var import_useTableQuery = __toESM(require("./hooks/useTableQuery"));
var import_useDataSource = __toESM(require("../hooks/useDataSource"));
var import_TableSettingProvider = __toESM(require("./provider/tableSetting/TableSettingProvider"));
var import_useDataSourceKey = __toESM(require("./hooks/useDataSourceKey"));
var import_useTableProps = __toESM(require("./hooks/useTableProps"));
var BaseTable = (props) => {
  const {
    columns: propsColumns,
    dataSource,
    operationContent,
    ...others
  } = props;
  const tableRef = (0, import_react.useRef)(null);
  const componentId = (0, import_useComponentId.default)(props);
  const { registerValueVariable } = (0, import_useVariables.default)();
  const { list } = (0, import_useDataSource.default)();
  const { data } = list;
  const { dataSourceKey, dataSourceKeyRef } = (0, import_useDataSourceKey.default)();
  const {
    drawerVisible,
    setDrawerVisible,
    openDrawer,
    closeDrawer,
    containerProps,
    Container,
    drawerContent
  } = (0, import_useDrawerState.default)(operationContent);
  const { queryPageConfig, handleValuesChange, refreshData, handleFilterChange } = (0, import_useTableQuery.default)(props);
  (0, import_useDesignMode.default)(props, {
    registerValueVariable,
    openDrawer,
    closeDrawer,
    data: data == null ? void 0 : data.data
  });
  (0, import_ahooks.useUpdateEffect)(() => {
    refreshData();
  }, [dataSourceKey]);
  (0, import_react.useEffect)(() => {
    if (dataSourceKeyRef.current) {
      list == null ? void 0 : list.run(queryPageConfig);
    } else {
      list == null ? void 0 : list.mutate([]);
    }
  }, [queryPageConfig]);
  (0, import_react.useEffect)(() => {
    registerValueVariable == null ? void 0 : registerValueVariable(componentId, {
      currentDataSource: dataSource
    });
  }, [dataSource]);
  const handleCloseDrawer = () => {
    closeDrawer();
    registerValueVariable == null ? void 0 : registerValueVariable(componentId, {
      currentRecord: null
    });
  };
  const transformProps = (0, import_useTableProps.default)({
    data,
    originProps: props,
    openDrawer,
    closeDrawer,
    refreshData,
    handleFilterChange,
    tableRef
  });
  return /* @__PURE__ */ import_react.default.createElement(import_TableSettingProvider.default, null, /* @__PURE__ */ import_react.default.createElement(
    import_table.default,
    {
      ref: tableRef,
      ...others,
      ...transformProps,
      dataSource: (data == null ? void 0 : data.data) || [],
      loading: list == null ? void 0 : list.loading,
      onValuesChange: handleValuesChange
    }
  ), /* @__PURE__ */ import_react.default.createElement(
    import_ActionsProvider.default,
    {
      visible: drawerVisible,
      setVisible: setDrawerVisible,
      refreshTableData: refreshData
    },
    /* @__PURE__ */ import_react.default.createElement(
      Container,
      {
        ...containerProps,
        open: drawerVisible,
        onClose: handleCloseDrawer,
        onCancel: handleCloseDrawer,
        destroyOnClose: true
      },
      drawerContent
    )
  ));
};
var BaseTable_default = BaseTable;
