import { _objectSpread2 } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import useEngineContext from "../../hooks/useEngineContext.js";
import { request } from "../../utils/index.js";
import { listApi } from "./serve.js";
import locales_default from "./locales.js";
import { getTableColumns } from "./config.js";
import Toolbar from "./components/Toolbar.js";
import OrderBatchActionBar from "./components/BatchActionBar.js";
import React, { useCallback, useMemo, useState } from "react";
import { locales } from "@pisell/utils";
import { Page, PisellDataSourceContainer, PisellGridPro, PisellGridView } from "@pisell/materials";
import "./index.less";
//#region src/plus/orderList/index.tsx
const OrderList = (props) => {
	var _context$engine, _context$appHelper, _window, _utils$getApp;
	const { biz, style, className, __id } = props;
	const context = useEngineContext();
	locales.init(locales_default, (context === null || context === void 0 || (_context$engine = context.engine) === null || _context$engine === void 0 || (_context$engine = _context$engine.props) === null || _context$engine === void 0 ? void 0 : _context$engine.locale) || "en");
	const tableColumns = useMemo(() => getTableColumns(locales), [locales]);
	const utils = (context === null || context === void 0 || (_context$appHelper = context.appHelper) === null || _context$appHelper === void 0 ? void 0 : _context$appHelper.utils) || {};
	request.setRequest(utils === null || utils === void 0 ? void 0 : utils.request);
	const useParams = (_window = window) === null || _window === void 0 || (_window = _window.app) === null || _window === void 0 || (_window = _window.history) === null || _window === void 0 ? void 0 : _window.useParams;
	const [selectedKeys, setSelectedKeys] = useState([]);
	const [selectedRows, setSelectedRows] = useState([]);
	const params = useParams === null || useParams === void 0 ? void 0 : useParams();
	const app = utils === null || utils === void 0 || (_utils$getApp = utils.getApp) === null || _utils$getApp === void 0 ? void 0 : _utils$getApp.call(utils);
	const extraParams = useMemo(() => {
		return { list: { business_code: biz || (params === null || params === void 0 ? void 0 : params.biz) } };
	}, [props.biz, params === null || params === void 0 ? void 0 : params.biz]);
	const tableConfig = useMemo(() => {
		return {
			columns: tableColumns,
			bordered: true,
			rowKey: "id",
			scroll: { x: "max-content" },
			size: "small",
			onRow: (record) => {
				return { onClick: () => {
					var _app$history;
					const pathname = encodeURIComponent((app === null || app === void 0 || (_app$history = app.history) === null || _app$history === void 0 || (_app$history = _app$history.instance) === null || _app$history === void 0 || (_app$history = _app$history.location) === null || _app$history === void 0 ? void 0 : _app$history.pathname) || "");
					app.history.push(`/order-detail?id=${record.id}&goback=${pathname}`);
				} };
			},
			rowSelection: {
				selectedRowKeys: selectedKeys,
				onChange: (selectedRowKeys, selectedRows) => {
					setSelectedKeys(selectedRowKeys);
					setSelectedRows(selectedRows);
				}
			}
		};
	}, [tableColumns, selectedKeys]);
	const batchActionBarConfig = useMemo(() => {
		return {
			locales,
			selectedKeys,
			selectedRows,
			onClearSelection: () => {
				setSelectedKeys([]);
				setSelectedRows([]);
			}
		};
	}, [
		locales,
		selectedKeys,
		selectedRows
	]);
	const clearSelectedData = useCallback(() => {
		setSelectedKeys([]);
		setSelectedRows([]);
	}, []);
	return /* @__PURE__ */ React.createElement(Page, {
		style: { height: "100%" },
		key: extraParams.list.business_code
	}, /* @__PURE__ */ React.createElement(PisellDataSourceContainer, {
		dataSource: { key: "orderList" },
		actions: { list: listApi },
		pagination: true,
		extraParams
	}, /* @__PURE__ */ React.createElement(PisellGridPro, {
		style: _objectSpread2({ height: "100vh" }, style),
		className
	}, /* @__PURE__ */ React.createElement(PisellGridPro.Header, { title: locales.getText("pisell2.orderList.title") }), /* @__PURE__ */ React.createElement(Toolbar, {
		clearSelectedData,
		__id,
		locales
	}), /* @__PURE__ */ React.createElement(PisellGridView, null, /* @__PURE__ */ React.createElement(PisellDataSourceContainer.Table, _objectSpread2(_objectSpread2({}, tableConfig), {}, { __id }))), /* @__PURE__ */ React.createElement(OrderBatchActionBar, batchActionBarConfig), /* @__PURE__ */ React.createElement(PisellGridPro.Footer, null, /* @__PURE__ */ React.createElement(PisellDataSourceContainer.Pagination, null)))));
};
//#endregion
export { OrderList as default };
