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_useEngineContext = require("../../../../hooks/useEngineContext.js");
const require_index = require("../../../../plus/productSelect/ProductCard/index.js");
const require_List = require("../../../list/List.js");
const require_useBigSaleProductListConfig = require("../../hooks/useBigSaleProductListConfig.js");
const require_index$1 = require("../../locales/index.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_utils = require("@pisell/utils");
require("./index.less");
//#region src/components/bigSale/components/ProductList/index.tsx
/**
* 商品列表只做“加载商品 + 触发加购”，加购决策交给 salesSdk。
*/
const BigSaleProductList = ({ dataSource, productLoadParams, productDisplayConfig, variant }) => {
	var _context$appHelper$ut, _context$appHelper$ut2, _context$appHelper$ut3;
	const context = require_useEngineContext.default();
	const { sales, products, cart } = dataSource;
	const { load } = products;
	const [keyword, setKeyword] = (0, react.useState)("");
	const currentProducts = products.products;
	const productListConfig = require_useBigSaleProductListConfig.useBigSaleProductListConfig({
		products: currentProducts,
		productDisplayConfig,
		variant,
		keyword
	});
	_pisell_utils.locales.init(require_index$1.default, ((_context$appHelper$ut = context.appHelper.utils) === null || _context$appHelper$ut === void 0 || (_context$appHelper$ut2 = _context$appHelper$ut.getApp) === null || _context$appHelper$ut2 === void 0 || (_context$appHelper$ut2 = _context$appHelper$ut2.call(_context$appHelper$ut)) === null || _context$appHelper$ut2 === void 0 || (_context$appHelper$ut2 = _context$appHelper$ut2.locales) === null || _context$appHelper$ut2 === void 0 || (_context$appHelper$ut3 = _context$appHelper$ut2.getLocale) === null || _context$appHelper$ut3 === void 0 ? void 0 : _context$appHelper$ut3.call(_context$appHelper$ut2)) || "en");
	(0, react.useEffect)(() => {
		if (!sales.isReady) return;
		load(productLoadParams).catch((error) => {
			console.error(error);
		});
	}, [
		sales.isReady,
		load,
		productLoadParams
	]);
	const handleSelectProduct = function() {
		var _ref = require_asyncToGenerator._asyncToGenerator(function* (product) {
			try {
				const result = yield cart.addProductWithFlow(product, { quantity: 1 });
				if (result.status === "requiresDetail" || result.status === "requiresBookingEdit") console.error(_pisell_utils.locales.getText("pisell2.big-sale.missing-hosts"));
			} catch (error) {
				console.error(error);
			}
		});
		return function handleSelectProduct(_x) {
			return _ref.apply(this, arguments);
		};
	}();
	return /* @__PURE__ */ react.default.createElement("div", { className: "pisell-big-sale-product-list-wrapper" }, /* @__PURE__ */ react.default.createElement(require_List.default, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({
		className: "pisell-big-sale-product-list",
		data: productListConfig.data,
		onTabSearch: setKeyword,
		loading: products.loading
	}, productListConfig.listProps), {}, {
		emptyConfig: {
			show: !products.loading && productListConfig.data.length === 0,
			text: _pisell_utils.locales.getText("pisell2.big-sale.no-products")
		},
		renderItem: (item, index) => /* @__PURE__ */ react.default.createElement(require_index.default, {
			key: item.id,
			index,
			item,
			onSelectCover: () => handleSelectProduct(item),
			onSelectInfo: () => handleSelectProduct(item),
			isSelected: false,
			scenario: "booking2",
			customSkuCardAllConfig: productListConfig.skuCardAllConfig
		})
	})));
};
//#endregion
exports.BigSaleProductList = BigSaleProductList;
