function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import React from 'react';
import OptionsCard from "../components/OptionsCard";
import NormalCard from "../components/NormalCard";
import TitleExtra from "../components/TitleExtra";
import { checkSkuDisabled, checkSkuStockCanSell } from "./checkSkuStatus";
import store from "../store/store";

// 定义基础数据类型（根据实际情况补充字段）

export var transformBundleGroup = function transformBundleGroup(bundleGroup) {
  var _store$getState$custo;
  if (!Array.isArray(bundleGroup)) return [];

  // 获取自定义Selector布局配置
  var selectorLayout = ((_store$getState$custo = store.getState().customConfig) === null || _store$getState$custo === void 0 ? void 0 : _store$getState$custo.selectorLayout) || null;
  var formattedGroup = bundleGroup.map(function (item) {
    var _item$bundle_item;
    // Selector中选项数据源
    var selectorOptionsDataSource = item === null || item === void 0 || (_item$bundle_item = item.bundle_item) === null || _item$bundle_item === void 0 ? void 0 : _item$bundle_item.map(function (bundleItem) {
      var _checkSkuStockCanSell = checkSkuStockCanSell(bundleItem),
        canSell = _checkSkuStockCanSell.canSell,
        hasStock = _checkSkuStockCanSell.hasStock;
      var disabled = checkSkuDisabled(bundleItem, canSell);
      return {
        _original: _objectSpread(_objectSpread({}, 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: 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: canSell,
          hasStock: hasStock,
          disabled: disabled
        }
      };
    });

    // Selector数据源
    var 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
      },
      layout: {
        type: 'antdGrid',
        columns: 2,
        gutter: [16, 16]
      },
      headerProps: {
        renderExtra: function renderExtra(props) {
          return /*#__PURE__*/React.createElement(TitleExtra, props || {});
        }
      },
      stepperProps: {
        horizontalPadding: '8px'
      }
    };
    if (!!selectorLayout) {
      selectorDataSource.layout = selectorLayout;
    }

    // 渲染选项卡片
    selectorDataSource.renderItem = function (itemProps) {
      var _itemProps$dataSource;
      // console.log('bundle_group_itemProps---', itemProps);
      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 && _itemProps$dataSource.length)) {
        return /*#__PURE__*/React.createElement(OptionsCard, _extends({}, itemProps || {}, {
          parentDataSource: selectorDataSource,
          mode: selectorDataSource === null || selectorDataSource === void 0 ? void 0 : selectorDataSource.mode
        }));
      }
      return /*#__PURE__*/React.createElement(NormalCard, _extends({}, itemProps || {}, {
        parentDataSource: selectorDataSource
      }));
    };
    return selectorDataSource;
  });
  return formattedGroup;
};