import { _objectSpread2 } from "../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import store from "../store/store.js";
import OptionsCard from "../components/OptionsCard/index.js";
import NormalCard from "../components/NormalCard/index.js";
import TitleExtra from "../components/TitleExtra/index.js";
import { checkSkuDisabled, checkSkuStockCanSell } from "./checkSkuStatus.js";
import React from "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 = store.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 } = checkSkuStockCanSell(bundleItem);
			const disabled = checkSkuDisabled(bundleItem, canSell);
			return {
				_original: _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.createElement(TitleExtra, 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.createElement(OptionsCard, _objectSpread2(_objectSpread2({}, itemProps || {}), {}, {
				parentDataSource: selectorDataSource,
				mode: selectorDataSource === null || selectorDataSource === void 0 ? void 0 : selectorDataSource.mode
			}));
			return /* @__PURE__ */ React.createElement(NormalCard, _objectSpread2(_objectSpread2({}, itemProps || {}), {}, { parentDataSource: selectorDataSource }));
		};
		return selectorDataSource;
	});
};
//#endregion
export { transformBundleGroup };
