const require_runtime = require("../../../../_virtual/_rolldown/runtime.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/DemoTabCreate.tsx
/**
* 新建 Tab：一键跑「createNew → loadCustomers → selectCustomer → loadProducts → addProductWithFlow
*          → recalcSummary → submit」全流程。
*
* 每步可单独执行，便于排查具体哪一步抛错；步骤间通过闭包传递上一步挑出的客户 / 商品引用。
* 真实接口（submit / addProduct）的副作用提示由顶部 banner 给出。
*/
const DemoTabCreate = () => {
	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 [override, setOverride] = (0, react.useState)({});
	const [editBookingError, setEditBookingError] = (0, react.useState)(null);
	const fixture = (0, react.useMemo)(() => require_fixtures.mergeMutableFixture(require_fixtures.FIXTURE_CREATE, override), [override]);
	const steps = (0, react.useMemo)(() => require_buildSteps.buildCreateSteps({
		sales,
		customer,
		products,
		cart
	}, fixture), [
		sales,
		customer,
		products,
		cart,
		fixture
	]);
	/** 清空 OS 空单 + 刷新 cart/summary 快照，避免 createNew 复用上一轮的 tempOrder / localStorage */
	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, "新建订单一键流程"), /* @__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 会调用真实 OS 接口（createNew / addProductWithFlow / submit）。加车若需规格会打开 Info2 弹窗。submit 会弹二次确认，其它步骤直接执行。")), /* @__PURE__ */ react.default.createElement(require_DemoAdvancedConfig.DemoAdvancedConfig, {
		variant: "create",
		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,
		onEditBookingError: (err) => {
			var _message;
			return setEditBookingError(String((_message = err === null || err === void 0 ? void 0 : err.message) !== null && _message !== void 0 ? _message : err));
		}
	}), editBookingError ? /* @__PURE__ */ react.default.createElement("section", { className: "sales-sdk-demo__panel sales-sdk-demo__panel--error" }, /* @__PURE__ */ react.default.createElement("h3", null, "编辑资源失败"), /* @__PURE__ */ react.default.createElement("pre", null, editBookingError)) : null, /* @__PURE__ */ react.default.createElement(require_RawSnapshotPanel.RawSnapshotPanel, {
		sales,
		cart,
		customer,
		summary: summaryState.summary,
		products: products.products
	}));
};
//#endregion
exports.DemoTabCreate = DemoTabCreate;
