const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_asyncToGenerator = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js");
const require_selectors = require("../../selectors.js");
const require_useSalesSdkCart = require("../../hooks/useSalesSdkCart.js");
const require_useSalesSdk = require("../../hooks/useSalesSdk.js");
const require_useSalesSdkCustomer = require("../../hooks/useSalesSdkCustomer.js");
const require_useSalesSdkSummary = require("../../hooks/useSalesSdkSummary.js");
const require_useSalesSdkProducts = require("../../hooks/useSalesSdkProducts.js");
const require_fixtures = require("../fixtures.js");
const require_RawSnapshotPanel = require("./RawSnapshotPanel.js");
const require_DemoAdvancedConfig = require("./DemoAdvancedConfig.js");
const require_CartPanel = require("./CartPanel.js");
const require_DemoStepRunner = require("./DemoStepRunner.js");
const require_buildSteps = require("./buildSteps.js");
let react = require("react");
react = require_runtime.__toESM(react);
let ahooks = require("ahooks");
//#region src/plus/salesSdk/demo/components/DemoTabEdit.tsx
/**
* 编辑 Tab：一键跑「loadDetail → setOrderNote → setShopDiscount → setContactsInfo
*          → loadCustomers → selectCustomer → loadProducts → addProductWithFlow
*          → recalcSummary → submit」全流程。
*
* 与新建 Tab 的差异：首步是 sales.loadDetail(orderId) 拉一份既有订单，后续在该 tempOrder
* 之上追加客户 / 商品 / submit。
*/
const DemoTabEdit = ({ initialOrderId }) => {
	const sales = require_useSalesSdk.useSalesSdk();
	const customer = require_useSalesSdkCustomer.useSalesSdkCustomer();
	const products = require_useSalesSdkProducts.useSalesSdkProducts();
	const cart = require_useSalesSdkCart.useSalesSdkCart();
	const summaryState = require_useSalesSdkSummary.useSalesSdkSummary();
	const initialFixture = (0, react.useMemo)(() => require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, require_fixtures.FIXTURE_EDIT), initialOrderId ? { orderId: initialOrderId } : {}), [initialOrderId]);
	const [override, setOverride] = (0, react.useState)({});
	const fixture = (0, react.useMemo)(() => {
		return require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, require_fixtures.mergeMutableFixture(initialFixture, override)), {}, { orderId: override.orderId != null ? Number(override.orderId) : initialFixture.orderId });
	}, [initialFixture, override]);
	const steps = (0, react.useMemo)(() => require_buildSteps.buildEditSteps({
		sales,
		customer,
		products,
		cart
	}, fixture), [
		sales,
		customer,
		products,
		cart,
		fixture
	]);
	const handleDemoReset = (0, ahooks.useMemoizedFn)(require_asyncToGenerator._asyncToGenerator(function* () {
		yield sales.restore();
		yield cart.recalcSummary();
	}));
	require_selectors.deriveSummary(summaryState.summary);
	return /* @__PURE__ */ react.default.createElement("section", { className: "sales-sdk-demo__tab" }, /* @__PURE__ */ react.default.createElement("header", { className: "sales-sdk-demo__panel sales-sdk-demo__panel--warn" }, /* @__PURE__ */ react.default.createElement("div", { className: "sales-sdk-demo__section-title" }, /* @__PURE__ */ react.default.createElement("h3", null, "编辑订单一键流程（orderId = ", fixture.orderId, "）"), /* @__PURE__ */ react.default.createElement("span", null, "status: ", sales.status, " / ready: ", sales.isReady ? "yes" : "no")), /* @__PURE__ */ react.default.createElement("p", { className: "sales-sdk-demo__hint" }, "注意：此 Tab 会先 loadDetail 加载既有订单，再写入备注 / 整单优惠 / 联系人，最后追加客户 / 商品 / submit，均为真实 OS 接口。")), /* @__PURE__ */ react.default.createElement(require_DemoAdvancedConfig.DemoAdvancedConfig, {
		variant: "edit",
		value: override,
		onChange: setOverride
	}), /* @__PURE__ */ react.default.createElement(require_DemoStepRunner.DemoStepRunner, {
		title: "步骤序列（点一键串行执行 / 也可单步）",
		steps,
		onReset: handleDemoReset
	}), sales.error ? /* @__PURE__ */ react.default.createElement("section", { className: "sales-sdk-demo__panel sales-sdk-demo__panel--error" }, /* @__PURE__ */ react.default.createElement("h3", null, "SDK Error"), /* @__PURE__ */ react.default.createElement("pre", null, sales.error.message)) : null, /* @__PURE__ */ react.default.createElement(require_CartPanel.CartPanel, { cart }), /* @__PURE__ */ react.default.createElement(require_RawSnapshotPanel.RawSnapshotPanel, {
		sales,
		cart,
		customer,
		summary: summaryState.summary,
		products: products.products
	}));
};
//#endregion
exports.DemoTabEdit = DemoTabEdit;
