var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/plus/skuOptionsSelection/utils/transformBundleGroup.tsx
var transformBundleGroup_exports = {};
__export(transformBundleGroup_exports, {
  transformBundleGroup: () => transformBundleGroup
});
module.exports = __toCommonJS(transformBundleGroup_exports);
var import_react = __toESM(require("react"));
var import_OptionsCard = __toESM(require("../components/OptionsCard"));
var import_NormalCard = __toESM(require("../components/NormalCard"));
var import_TitleExtra = __toESM(require("../components/TitleExtra"));
var import_checkSkuStatus = require("./checkSkuStatus");
var import_store = __toESM(require("../store/store"));
var transformBundleGroup = (bundleGroup) => {
  var _a;
  if (!Array.isArray(bundleGroup)) return [];
  const selectorLayout = ((_a = import_store.default.getState().customConfig) == null ? void 0 : _a.selectorLayout) || null;
  const formattedGroup = bundleGroup.map((item) => {
    var _a2;
    const selectorOptionsDataSource = (_a2 = item == null ? void 0 : item.bundle_item) == null ? void 0 : _a2.map((bundleItem) => {
      const { canSell, hasStock } = (0, import_checkSkuStatus.checkSkuStockCanSell)(bundleItem);
      const disabled = (0, import_checkSkuStatus.checkSkuDisabled)(bundleItem, canSell);
      return {
        _original: {
          ...bundleItem || {},
          _bundle_product_id: bundleItem == null ? void 0 : bundleItem.bundle_product_id
        },
        // 渲染需要的数据源
        id: bundleItem == null ? void 0 : bundleItem.id,
        title: (bundleItem == null ? void 0 : bundleItem.title) || "",
        value: (bundleItem == null ? void 0 : bundleItem.id) || "",
        disabled,
        ruleConfig: {
          min: bundleItem == null ? void 0 : bundleItem.min_quantity,
          max: bundleItem == null ? void 0 : bundleItem.max_quantity,
          autoValidate: true
        },
        _extra: { canSell, hasStock, disabled }
      };
    });
    const selectorDataSource = {
      id: item.id,
      title: (item == null ? void 0 : item.name) || "",
      mode: (item == null ? void 0 : item.max_quantity) === 1 ? "single" : "multiple",
      valueType: "object",
      fieldNames: { value: "value", label: "title" },
      dataSource: selectorOptionsDataSource || [],
      disabled: (item == null ? void 0 : item.is_enabled) === 0,
      ruleConfig: {
        min: item == null ? void 0 : item.min_quantity,
        max: item == null ? void 0 : item.max_quantity,
        autoValidate: true,
        required: Number(item == null ? void 0 : item.min_quantity) > 0 ? true : false
      },
      layout: {
        type: "antdGrid",
        columns: 2,
        gutter: [16, 16]
      },
      headerProps: {
        renderExtra: (props) => {
          return /* @__PURE__ */ import_react.default.createElement(import_TitleExtra.default, { ...props || {} });
        }
      },
      stepperProps: {
        horizontalPadding: "8px"
      }
    };
    if (!!selectorLayout) {
      selectorDataSource.layout = selectorLayout;
    }
    selectorDataSource.renderItem = (itemProps) => {
      var _a3, _b, _c;
      if (!!((_c = (_b = (_a3 = itemProps == null ? void 0 : itemProps.dataSource) == null ? void 0 : _a3._original) == null ? void 0 : _b.option_group) == null ? void 0 : _c.length)) {
        return /* @__PURE__ */ import_react.default.createElement(
          import_OptionsCard.default,
          {
            ...itemProps || {},
            parentDataSource: selectorDataSource,
            mode: selectorDataSource == null ? void 0 : selectorDataSource.mode
          }
        );
      }
      return /* @__PURE__ */ import_react.default.createElement(
        import_NormalCard.default,
        {
          ...itemProps || {},
          parentDataSource: selectorDataSource
        }
      );
    };
    return selectorDataSource;
  });
  return formattedGroup;
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  transformBundleGroup
});
