const require_runtime = require("../../_virtual/_rolldown/runtime.js");
const require_withResponsive = require("../../responsive/withResponsive.js");
const require_useBigSaleDataSource = require("./hooks/useBigSaleDataSource.js");
const require_index = require("./templates/index.js");
let react = require("react");
react = require_runtime.__toESM(react);
let classnames = require("classnames");
classnames = require_runtime.__toESM(classnames);
//#region src/components/bigSale/Base.tsx
const DEFAULT_MODE = "ticket";
const SECONDARY_SCREEN_HIDDEN_SALE_DETAIL_MODULES = ["cartActions", "orderActions"];
function getSaleDetailModuleConfig({ template }) {
	if (template !== "secondaryScreen") return void 0;
	return {
		hidden: SECONDARY_SCREEN_HIDDEN_SALE_DETAIL_MODULES,
		amountDetails: { defaultExpanded: true }
	};
}
/**
* BigSaleBase 位于 SalesSdkProvider 内部，负责把 SDK 数据分发给商品列表和 SaleDetailBase。
*/
function BigSaleBase({ className, style, mode = DEFAULT_MODE, tmpl, template = "standard", variant = "desktop", productLoadParams, productDisplayConfig, saleDetailTemplate, autoCreate = true, orderId, locale, saleDetailWrapperProps }) {
	const dataSource = require_useBigSaleDataSource.useBigSaleDataSource();
	const currentTemplate = tmpl || template || "standard";
	const autoCreateStartedRef = (0, react.useRef)(false);
	const resolvedSaleDetailModuleConfig = (0, react.useMemo)(() => getSaleDetailModuleConfig({ template: currentTemplate }), [currentTemplate]);
	const isSecondaryTemplate = currentTemplate === "secondaryScreen";
	(0, react.useEffect)(() => {
		if (!autoCreate || orderId || autoCreateStartedRef.current) return;
		if (!dataSource.sales.bookingTicket || dataSource.sales.tempOrder) return;
		if (dataSource.sales.status !== "idle") return;
		autoCreateStartedRef.current = true;
		dataSource.sales.createNew().catch(() => {
			autoCreateStartedRef.current = false;
		});
	}, [
		autoCreate,
		orderId,
		dataSource.sales,
		dataSource.sales.bookingTicket,
		dataSource.sales.status,
		dataSource.sales.tempOrder
	]);
	return /* @__PURE__ */ react.default.createElement("div", {
		className: (0, classnames.default)("pisell-big-sale", `pisell-big-sale--${variant}`, `pisell-big-sale-tmpl--${currentTemplate}`, { "pisell-big-sale--secondary-screen": isSecondaryTemplate }, className),
		style
	}, /* @__PURE__ */ react.default.createElement(require_index.BigSaleTemplateRenderer, {
		mode,
		tmpl: currentTemplate,
		variant,
		dataSource,
		productLoadParams,
		productDisplayConfig,
		saleDetailTemplate,
		saleDetailModuleConfig: resolvedSaleDetailModuleConfig,
		orderId,
		locale,
		saleDetailWrapperProps: isSecondaryTemplate ? saleDetailWrapperProps : void 0
	}));
}
BigSaleBase.displayName = "BigSaleBase";
const ResponsiveBigSaleBase = require_withResponsive.default(BigSaleBase);
//#endregion
exports.ResponsiveBigSaleBase = ResponsiveBigSaleBase;
