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/plus/orderList/index.tsx
var orderList_exports = {};
__export(orderList_exports, {
  default: () => orderList_default
});
module.exports = __toCommonJS(orderList_exports);
var import_react = __toESM(require("react"));
var import_config = require("./config");
var import_Toolbar = __toESM(require("./components/Toolbar"));
var import_BatchActionBar = __toESM(require("./components/BatchActionBar"));
var import_utils = require("@pisell/utils");
var import_locales = __toESM(require("./locales"));
var import_useEngineContext = __toESM(require("../../hooks/useEngineContext"));
var import_serve = require("./serve");
var import_utils2 = require("../../utils");
var import_index = require("./index.less");
var import_materials = require("@pisell/materials");
var OrderList = (props) => {
  var _a, _b, _c, _d, _e, _f;
  const { biz, style, className, __id } = props;
  const context = (0, import_useEngineContext.default)();
  import_utils.locales.init(import_locales.default, ((_b = (_a = context == null ? void 0 : context.engine) == null ? void 0 : _a.props) == null ? void 0 : _b.locale) || "en");
  const tableColumns = (0, import_react.useMemo)(() => (0, import_config.getTableColumns)(import_utils.locales), [import_utils.locales]);
  const utils = ((_c = context == null ? void 0 : context.appHelper) == null ? void 0 : _c.utils) || {};
  import_utils2.request.setRequest(utils == null ? void 0 : utils.request);
  const useParams = (_e = (_d = window == null ? void 0 : window.app) == null ? void 0 : _d.history) == null ? void 0 : _e.useParams;
  const [selectedKeys, setSelectedKeys] = (0, import_react.useState)([]);
  const [selectedRows, setSelectedRows] = (0, import_react.useState)([]);
  const params = useParams == null ? void 0 : useParams();
  const app = (_f = utils == null ? void 0 : utils.getApp) == null ? void 0 : _f.call(utils);
  const extraParams = (0, import_react.useMemo)(() => {
    return {
      // 优先props的biz  --> 内置从路由上取
      list: { business_code: biz || (params == null ? void 0 : params.biz) }
    };
  }, [props.biz, params == null ? void 0 : params.biz]);
  const tableConfig = (0, import_react.useMemo)(() => {
    return {
      columns: tableColumns,
      bordered: true,
      rowKey: "id",
      scroll: { x: "max-content" },
      size: "small",
      onRow: (record) => {
        return {
          onClick: () => {
            var _a2, _b2, _c2;
            const pathname = encodeURIComponent(((_c2 = (_b2 = (_a2 = app == null ? void 0 : app.history) == null ? void 0 : _a2.instance) == null ? void 0 : _b2.location) == null ? void 0 : _c2.pathname) || "");
            app.history.push(`/order-detail?id=${record.id}&goback=${pathname}`);
          }
        };
      },
      rowSelection: {
        selectedRowKeys: selectedKeys,
        onChange: (selectedRowKeys, selectedRows2) => {
          setSelectedKeys(selectedRowKeys);
          setSelectedRows(selectedRows2);
        }
      }
    };
  }, [tableColumns, selectedKeys]);
  const batchActionBarConfig = (0, import_react.useMemo)(() => {
    return {
      locales: import_utils.locales,
      selectedKeys,
      selectedRows,
      onClearSelection: () => {
        setSelectedKeys([]);
        setSelectedRows([]);
      }
    };
  }, [import_utils.locales, selectedKeys, selectedRows]);
  const clearSelectedData = (0, import_react.useCallback)(() => {
    setSelectedKeys([]);
    setSelectedRows([]);
  }, []);
  return /* @__PURE__ */ import_react.default.createElement(import_materials.Page, { style: { height: "100%" }, key: extraParams.list.business_code }, /* @__PURE__ */ import_react.default.createElement(
    import_materials.PisellDataSourceContainer,
    {
      dataSource: { key: "orderList" },
      actions: { list: import_serve.listApi },
      pagination: true,
      extraParams
    },
    /* @__PURE__ */ import_react.default.createElement(
      import_materials.PisellGridPro,
      {
        style: { height: "100vh", ...style },
        className
      },
      /* @__PURE__ */ import_react.default.createElement(
        import_materials.PisellGridPro.Header,
        {
          title: import_utils.locales.getText("pisell2.orderList.title")
        }
      ),
      /* @__PURE__ */ import_react.default.createElement(import_Toolbar.default, { clearSelectedData, __id, locales: import_utils.locales }),
      /* @__PURE__ */ import_react.default.createElement(import_materials.PisellGridView, null, /* @__PURE__ */ import_react.default.createElement(import_materials.PisellDataSourceContainer.Table, { ...tableConfig, __id })),
      /* @__PURE__ */ import_react.default.createElement(import_BatchActionBar.default, { ...batchActionBarConfig }),
      /* @__PURE__ */ import_react.default.createElement(import_materials.PisellGridPro.Footer, null, /* @__PURE__ */ import_react.default.createElement(import_materials.PisellDataSourceContainer.Pagination, null))
    )
  ));
};
var orderList_default = OrderList;
