const require_runtime = require("../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_store = require("../store/store.js");
const require_index = require("../components/OptionsCard/index.js");
const require_index$1 = require("../components/NormalCard/index.js");
const require_index$2 = require("../components/TitleExtra/index.js");
const require_checkSkuStatus = require("./checkSkuStatus.js");
let react = require("react");
react = require_runtime.__toESM(react);
//#region src/plus/skuOptionsSelection/utils/transformBundleGroup.tsx
const transformBundleGroup = (bundleGroup) => {
	var _store$getState$custo;
	if (!Array.isArray(bundleGroup)) return [];
	const selectorLayout = ((_store$getState$custo = require_store.default.getState().customConfig) === null || _store$getState$custo === void 0 ? void 0 : _store$getState$custo.selectorLayout) || null;
	return bundleGroup.map((item) => {
		var _item$bundle_item;
		const selectorOptionsDataSource = item === null || item === void 0 || (_item$bundle_item = item.bundle_item) === null || _item$bundle_item === void 0 ? void 0 : _item$bundle_item.map((bundleItem) => {
			const { canSell, hasStock } = require_checkSkuStatus.checkSkuStockCanSell(bundleItem);
			const disabled = require_checkSkuStatus.checkSkuDisabled(bundleItem, canSell);
			return {
				_original: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, bundleItem || {}), {}, { _bundle_product_id: bundleItem === null || bundleItem === void 0 ? void 0 : bundleItem.bundle_product_id }),
				id: bundleItem === null || bundleItem === void 0 ? void 0 : bundleItem.id,
				title: (bundleItem === null || bundleItem === void 0 ? void 0 : bundleItem.title) || "",
				value: (bundleItem === null || bundleItem === void 0 ? void 0 : bundleItem.id) || "",
				disabled,
				ruleConfig: {
					min: bundleItem === null || bundleItem === void 0 ? void 0 : bundleItem.min_quantity,
					max: bundleItem === null || bundleItem === void 0 ? void 0 : bundleItem.max_quantity,
					autoValidate: true
				},
				_extra: {
					canSell,
					hasStock,
					disabled
				}
			};
		});
		const selectorDataSource = {
			id: item.id,
			title: (item === null || item === void 0 ? void 0 : item.name) || "",
			mode: (item === null || item === void 0 ? void 0 : item.max_quantity) === 1 ? "single" : "multiple",
			valueType: "object",
			fieldNames: {
				value: "value",
				label: "title"
			},
			dataSource: selectorOptionsDataSource || [],
			disabled: (item === null || item === void 0 ? void 0 : item.is_enabled) === 0,
			ruleConfig: {
				min: item === null || item === void 0 ? void 0 : item.min_quantity,
				max: item === null || item === void 0 ? void 0 : item.max_quantity,
				autoValidate: true,
				required: Number(item === null || item === void 0 ? void 0 : item.min_quantity) > 0 ? true : false
			},
			headerProps: { renderExtra: (props) => {
				return /* @__PURE__ */ react.default.createElement(require_index$2.default, props || {});
			} },
			stepperProps: { horizontalPadding: "8px" }
		};
		if (!!selectorLayout) selectorDataSource.layout = selectorLayout;
		selectorDataSource.renderItem = (itemProps) => {
			var _itemProps$dataSource;
			if (!!(itemProps === null || itemProps === void 0 || (_itemProps$dataSource = itemProps.dataSource) === null || _itemProps$dataSource === void 0 || (_itemProps$dataSource = _itemProps$dataSource._original) === null || _itemProps$dataSource === void 0 || (_itemProps$dataSource = _itemProps$dataSource.option_group) === null || _itemProps$dataSource === void 0 ? void 0 : _itemProps$dataSource.length)) return /* @__PURE__ */ react.default.createElement(require_index.default, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, itemProps || {}), {}, {
				parentDataSource: selectorDataSource,
				mode: selectorDataSource === null || selectorDataSource === void 0 ? void 0 : selectorDataSource.mode
			}));
			return /* @__PURE__ */ react.default.createElement(require_index$1.default, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, itemProps || {}), {}, { parentDataSource: selectorDataSource }));
		};
		return selectorDataSource;
	});
};
//#endregion
exports.transformBundleGroup = transformBundleGroup;
