"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const React = require("react");
const emotionReactJsxRuntime_browser_esm = require("../node_modules/.pnpm/@emotion_react@11.10.4_q4mq7tnhdumujvomvw24zx33y4/node_modules/@emotion/react/jsx-runtime/dist/emotion-react-jsx-runtime.browser.esm.js");
const index = require("../node_modules/.pnpm/@arco-design_web-react@2.40.1_biqbaboplfbrettd7655fr4n2y/node_modules/@arco-design/web-react/es/Table/index.js");
const Tables = ({
  url,
  fetcher,
  queryWhere,
  actions = [],
  ...props
}) => {
  const {
    id,
    name,
    fragment,
    columns
  } = props || {};
  const {
    data,
    total
  } = fetcher.data || {};
  const [pagination, setPatination] = React.useState({
    sizeCanChange: true,
    showTotal: true,
    pageSize: 20,
    current: 1,
    pageSizeChangeResetCurrent: true
  });
  React.useEffect(() => {
    fetchData();
  }, [id, pagination.current, pagination.pageSize, JSON.stringify(queryWhere)]);
  React.useEffect(() => {
    if (total) {
      setPatination({
        ...pagination,
        total
      });
    }
  }, [total]);
  function fetchData() {
    const {
      current,
      pageSize
    } = pagination;
    console.log("fetchData", {
      current,
      pageSize,
      formParams: JSON.stringify(queryWhere),
      tableName: name,
      fragment,
      action: "load"
    });
    fetcher.submit({
      current,
      pageSize,
      formParams: JSON.stringify(queryWhere),
      tableName: name,
      fragment,
      action: "load"
    }, {
      method: "post",
      replace: true,
      action: url || `/api/crud/${id}`
    });
  }
  function onChangeTable(pagination2) {
    console.log("onChangeTable-->", JSON.stringify(pagination2));
    const {
      current,
      pageSize
    } = pagination2;
    setPatination({
      ...pagination2,
      current,
      pageSize
    });
  }
  return /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("div", {
    className: "relative flex-1 mb-6",
    children: /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(index, {
      rowKey: "id",
      loading: fetcher.state === "loading",
      onChange: onChangeTable,
      pagination,
      columns: [...columns, ...actions],
      data
    })
  });
};
exports.Tables = Tables;
//# sourceMappingURL=Tables.js.map
