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/transformOptionGroup.tsx
var transformOptionGroup_exports = {};
__export(transformOptionGroup_exports, {
  transformOptionGroup: () => transformOptionGroup
});
module.exports = __toCommonJS(transformOptionGroup_exports);
var import_react = __toESM(require("react"));
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 transformOptionGroup = (optionGroup) => {
  var _a;
  if (!Array.isArray(optionGroup)) return [];
  const selectorLayout = ((_a = import_store.default.getState().customConfig) == null ? void 0 : _a.selectorLayout) || null;
  const formattedGroup = optionGroup.map((item) => {
    var _a2;
    const selectorOptionsDataSource = (_a2 = item == null ? void 0 : item.option_item) == null ? void 0 : _a2.map(
      (optionItem) => {
        const { canSell, hasStock } = (0, import_checkSkuStatus.checkSkuStockCanSell)(optionItem);
        const disabled = (0, import_checkSkuStatus.checkSkuDisabled)(optionItem, canSell);
        return {
          _original: {
            ...optionItem || {},
            product_option_item_id: optionItem == null ? void 0 : optionItem.id
          },
          id: optionItem == null ? void 0 : optionItem.id,
          title: optionItem == null ? void 0 : optionItem.name,
          value: optionItem == null ? void 0 : optionItem.id,
          disabled,
          ruleConfig: {
            min: optionItem == null ? void 0 : optionItem.min_quantity,
            max: optionItem == null ? void 0 : optionItem.max_quantity,
            autoValidate: true
          },
          _extra: { canSell, hasStock, disabled }
        };
      }
    );
    const isMultiple = (item == null ? 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 ? void 0 : item.is_enabled) === 0,
      ruleConfig: {
        // 多选时以设置为准；单选时不限制
        min: isMultiple ? item == null ? void 0 : item.min_quantity : void 0,
        // 多选时，max为0时表示不限制最大选择数量；单选时不限制最大选择数量
        max: isMultiple ? Number(item == null ? void 0 : item.max_quantity) == 0 ? void 0 : item == null ? void 0 : item.max_quantity : void 0,
        autoValidate: true,
        // 单规格必选判定分成两种：
        // 1. 未开启多选时以：item?.required === 1 为准
        // 2. 开启多选时以：item?.min_quantity > 0 为准
        required: isMultiple ? Number((item == null ? void 0 : item.min_quantity) || 0) > 0 : (item == null ? void 0 : item.required) === 1
      },
      headerProps: {
        renderExtra: (props) => {
          return /* @__PURE__ */ import_react.default.createElement(import_TitleExtra.default, { ...props || {} });
        }
      },
      stepperProps: {
        horizontalPadding: "8px"
      }
    };
    if (!!selectorLayout) {
      selectorDataSource.layout = selectorLayout;
    }
    selectorDataSource.renderItem = (itemProps) => {
      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 = {
  transformOptionGroup
});
