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/NormalCard/index.js");
const require_index$1 = 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/transformOptionGroup.tsx
const transformOptionGroup = (optionGroup) => {
	var _store$getState$custo;
	if (!Array.isArray(optionGroup)) 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 optionGroup.map((item) => {
		var _item$option_item;
		const selectorOptionsDataSource = item === null || item === void 0 || (_item$option_item = item.option_item) === null || _item$option_item === void 0 ? void 0 : _item$option_item.map((optionItem) => {
			const { canSell, hasStock } = require_checkSkuStatus.checkSkuStockCanSell(optionItem);
			const disabled = require_checkSkuStatus.checkSkuDisabled(optionItem, canSell);
			return {
				_original: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, optionItem || {}), {}, { product_option_item_id: optionItem === null || optionItem === void 0 ? void 0 : optionItem.id }),
				id: optionItem === null || optionItem === void 0 ? void 0 : optionItem.id,
				title: optionItem === null || optionItem === void 0 ? void 0 : optionItem.name,
				value: optionItem === null || optionItem === void 0 ? void 0 : optionItem.id,
				disabled,
				ruleConfig: {
					min: optionItem === null || optionItem === void 0 ? void 0 : optionItem.min_quantity,
					max: optionItem === null || optionItem === void 0 ? void 0 : optionItem.max_quantity,
					autoValidate: true
				},
				_extra: {
					canSell,
					hasStock,
					disabled
				}
			};
		});
		const isMultiple = (item === null || item === void 0 ? void 0 : item.is_multiple) == 1;
		const selectorDataSource = {
			id: item.id,
			title: item.name || "",
			mode: isMultiple ? "multiple" : "single",
			valueType: "object",
			fieldNames: {
				value: "value",
				label: "title"
			},
			dataSource: selectorOptionsDataSource || [],
			disabled: (item === null || item === void 0 ? void 0 : item.is_enabled) === 0,
			ruleConfig: {
				min: isMultiple ? item === null || item === void 0 ? void 0 : item.min_quantity : void 0,
				max: isMultiple ? Number(item === null || item === void 0 ? void 0 : item.max_quantity) == 0 ? void 0 : item === null || item === void 0 ? void 0 : item.max_quantity : void 0,
				autoValidate: true,
				required: isMultiple ? Number((item === null || item === void 0 ? void 0 : item.min_quantity) || 0) > 0 : (item === null || item === void 0 ? void 0 : item.required) === 1
			},
			headerProps: { renderExtra: (props) => {
				return /* @__PURE__ */ react.default.createElement(require_index$1.default, props || {});
			} },
			stepperProps: { horizontalPadding: "8px" }
		};
		if (!!selectorLayout) selectorDataSource.layout = selectorLayout;
		selectorDataSource.renderItem = (itemProps) => {
			return /* @__PURE__ */ react.default.createElement(require_index.default, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, itemProps || {}), {}, { parentDataSource: selectorDataSource }));
		};
		return selectorDataSource;
	});
};
//#endregion
exports.transformOptionGroup = transformOptionGroup;
