function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
/**
 * 获取商品的可用资源
 * @param product 商品数据
 * @returns 可用资源
 */
export var getAvailableProductResources = function getAvailableProductResources(products) {
  var rules = []; // 每个商品对应的预约规则
  var resourcesMap = {}; // 每个资源对应的商品
  var resourceIds = []; // 所有商品的资源id
  products.forEach(function (product) {
    var _product$product_reso, _product$product_reso2;
    var tempResourceIds = [];
    product === null || product === void 0 || (_product$product_reso = product.product_resource) === null || _product$product_reso === void 0 || (_product$product_reso = _product$product_reso.resources) === null || _product$product_reso === void 0 || (_product$product_reso2 = _product$product_reso.forEach) === null || _product$product_reso2 === void 0 || _product$product_reso2.call(_product$product_reso, function (resource) {
      if ((resource === null || resource === void 0 ? void 0 : resource.status) == 1) {
        var _resource$default_res, _resource$optional_re;
        tempResourceIds.push(resource === null || resource === void 0 ? void 0 : resource.id);
        if (!resourcesMap[resource === null || resource === void 0 ? void 0 : resource.id]) {
          resourcesMap[resource === null || resource === void 0 ? void 0 : resource.id] = resource;
        }
        if (resource !== null && resource !== void 0 && (_resource$default_res = resource.default_resource) !== null && _resource$default_res !== void 0 && _resource$default_res.length) {
          resourceIds.push.apply(resourceIds, _toConsumableArray(resource === null || resource === void 0 ? void 0 : resource.default_resource));
        } else if (resource !== null && resource !== void 0 && (_resource$optional_re = resource.optional_resource) !== null && _resource$optional_re !== void 0 && _resource$optional_re.length) {
          resourceIds.push.apply(resourceIds, _toConsumableArray(resource === null || resource === void 0 ? void 0 : resource.optional_resource));
        }
      }
    });
    var rule = {};
    if (product !== null && product !== void 0 && product.cut_off_time) {
      rule.cut_off_time = product === null || product === void 0 ? void 0 : product.cut_off_time;
    }
    if (tempResourceIds) {
      rule.resourceFormIds = _toConsumableArray(new Set(tempResourceIds));
    }
    if (product !== null && product !== void 0 && product._schedule) {
      rule.schedule = product === null || product === void 0 ? void 0 : product._schedule;
    }
    rules.push(rule);
  });
  return {
    resourceIds: _toConsumableArray(new Set(resourceIds)),
    rules: rules,
    resourcesMap: resourcesMap
  };
};

/**
 * 判断商品是否是 session 商品
 * @param product 商品数据
 * @returns 是否是 session 商品
 */
export var isSessionProduct = function isSessionProduct(product) {
  var _product$scheduleIds, _product$scheduleIds2;
  return ((_product$scheduleIds = product === null || product === void 0 || (_product$scheduleIds2 = product['schedule.ids']) === null || _product$scheduleIds2 === void 0 ? void 0 : _product$scheduleIds2.length) !== null && _product$scheduleIds !== void 0 ? _product$scheduleIds : 0) > 0;
};