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 { getRelationTables } from "./serve.js";
import pisellSalesGrid_default from "../pisellSalesGrid/index.js";
import locales_default from "../orderList/locales.js";
import locales_default$1 from "./locales.js";
import usePerspectives from "./hooks/usePerspectives.js";
import { useSalesGridData } from "./hooks/useSalesGridData.js";
import React, { useEffect, useMemo } from "react";
import { locales } from "@pisell/utils";
import { PisellConfigProvider } from "@pisell/materials";
import { useRequest } from "ahooks";
import { LocalizationProvider } from "@pisell/date-picker";
import { AdapterDayjs } from "@pisell/date-picker/es/AdapterDayjs";
//#region src/plus/pisellSalesManagement/index.tsx
const PisellSalesManagement = (props) => {
	var _context$appHelper, _context$engine, _window, _context$engine2, _context$engine3, _context$engine4, _context$engine5, _context$engine6;
	const { perspective, __id } = props;
	const context = useEngineContext();
	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 _getRelationTables = useRequest(getRelationTables);
	const mergedLocales = {
		en: _objectSpread2(_objectSpread2({}, locales_default.en), locales_default$1.en),
		"zh-CN": _objectSpread2(_objectSpread2({}, locales_default["zh-CN"]), locales_default$1["zh-CN"]),
		"zh-HK": _objectSpread2(_objectSpread2({}, locales_default["zh-HK"]), locales_default$1["zh-HK"])
	};
	locales.init(mergedLocales, (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");
	useEffect(() => {
		if (perspective === "monitor") setTimeout(() => {
			utils.action({ type: "pisell1.registerBookingPlugin" });
		}, 300);
	}, [perspective, utils]);
	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 params = useParams === null || useParams === void 0 ? void 0 : useParams();
	const queryBusinessCode = useMemo(() => {
		if (typeof window === "undefined") return void 0;
		return new URLSearchParams(window.location.search || "").get("business_code") || void 0;
	}, []);
	const extParams = useMemo(() => {
		return { list: { business_code: props.biz || (params === null || params === void 0 ? void 0 : params.biz) || queryBusinessCode } };
	}, [
		props.biz,
		params === null || params === void 0 ? void 0 : params.biz,
		queryBusinessCode
	]);
	const perspectives = usePerspectives({ relationTables: _getRelationTables.data || [] });
	const gridDataProps = useSalesGridData({
		perspective,
		extParams
	});
	const adapterLocale = (context === null || context === void 0 || (_context$engine2 = context.engine) === null || _context$engine2 === void 0 || (_context$engine2 = _context$engine2.props) === null || _context$engine2 === void 0 ? void 0 : _context$engine2.locale) === "zh-CN" || (context === null || context === void 0 || (_context$engine3 = context.engine) === null || _context$engine3 === void 0 || (_context$engine3 = _context$engine3.props) === null || _context$engine3 === void 0 ? void 0 : _context$engine3.locale) === "zh-HK" ? "zh-cn" : (context === null || context === void 0 || (_context$engine4 = context.engine) === null || _context$engine4 === void 0 || (_context$engine4 = _context$engine4.props) === null || _context$engine4 === void 0 ? void 0 : _context$engine4.locale) === "en" || (context === null || context === void 0 || (_context$engine5 = context.engine) === null || _context$engine5 === void 0 || (_context$engine5 = _context$engine5.props) === null || _context$engine5 === void 0 ? void 0 : _context$engine5.locale) === "en-US" ? "en" : "zh-cn";
	const rawLocale = (context === null || context === void 0 || (_context$engine6 = context.engine) === null || _context$engine6 === void 0 || (_context$engine6 = _context$engine6.props) === null || _context$engine6 === void 0 ? void 0 : _context$engine6.locale) || (typeof localStorage !== "undefined" ? localStorage.getItem("umi_locale") : null) || "en-US";
	const materialsLocale = rawLocale === "zh" ? "zh-CN" : rawLocale;
	return /* @__PURE__ */ React.createElement(PisellConfigProvider, { locale: materialsLocale }, /* @__PURE__ */ React.createElement(LocalizationProvider, {
		dateAdapter: AdapterDayjs,
		adapterLocale
	}, /* @__PURE__ */ React.createElement("div", { style: Object.assign({}, { height: 0 }, props === null || props === void 0 ? void 0 : props.style) }, /* @__PURE__ */ React.createElement(pisellSalesGrid_default, {
		perspectives,
		currentPerspective: perspective,
		extParams,
		__id,
		data: gridDataProps.data,
		loading: gridDataProps.loading,
		total: gridDataProps.total,
		pagination: gridDataProps.pagination,
		onPageChange: gridDataProps.onPageChange,
		searchParams: gridDataProps.searchParams,
		onSearch: gridDataProps.onSearch,
		onReset: gridDataProps.onReset,
		selectedKeys: gridDataProps.selectedKeys,
		selectedRows: gridDataProps.selectedRows,
		onSelectionChange: gridDataProps.onSelectionChange,
		rowKey: gridDataProps.rowKey,
		onRefresh: gridDataProps.onRefresh,
		refreshAsync: gridDataProps.refreshAsync
	}))));
};
//#endregion
export { PisellSalesManagement as default };
