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/checkSkuStatus.ts
var checkSkuStatus_exports = {};
__export(checkSkuStatus_exports, {
  checkSkuDisabled: () => checkSkuDisabled,
  checkSkuStockCanSell: () => checkSkuStockCanSell,
  checkVariantStockByValue: () => checkVariantStockByValue,
  checkVariantStockCanSell: () => checkVariantStockCanSell
});
module.exports = __toCommonJS(checkSkuStatus_exports);
var import_store = __toESM(require("../store/store"));
var checkSkuStockCanSell = (sku) => {
  var _a;
  let canSell = true;
  let hasStock = true;
  if ((sku == null ? void 0 : sku.is_track) === 1) {
    if ((sku == null ? void 0 : sku.over_sold) === 1 || ((_a = import_store.default.getState().config) == null ? void 0 : _a.overSold)) {
      canSell = true;
      hasStock = Number((sku == null ? void 0 : sku.stock_quantity) || 0) > 0;
    } else {
      if (Number((sku == null ? void 0 : sku.stock_quantity) || 0) <= 0) {
        canSell = false;
        hasStock = false;
      }
    }
  } else {
    canSell = true;
    hasStock = true;
  }
  return { canSell, hasStock };
};
var checkSkuDisabled = (sku, canSell = true) => {
  return (sku == null ? void 0 : sku.is_enabled) === 0 || !canSell;
};
var checkVariantStockCanSell = (sku) => {
  const dataSource = import_store.default.getState().dataSource;
  const variant = (dataSource == null ? void 0 : dataSource.variant) || [];
  const variantSkuId = `${sku == null ? void 0 : sku.variant_group_id}:${sku == null ? void 0 : sku.id}`;
  const matchedVariants = variant.filter((item) => {
    var _a;
    const ids = ((_a = item == null ? void 0 : item.sku_ids) == null ? void 0 : _a.split("_")) || [];
    return ids.includes(variantSkuId);
  });
  if (matchedVariants.length === 0) {
    return { canSell: false, hasStock: false };
  }
  const results = matchedVariants.map((item) => checkSkuStockCanSell(item));
  return {
    // 只要有一个能售卖则可选
    canSell: results.some((r) => r.canSell),
    // 只要有一个有库存则显示有库存
    hasStock: results.some((r) => r.hasStock)
  };
};
var checkVariantStockByValue = (sku) => {
  var _a;
  const dataSource = import_store.default.getState().dataSource;
  const variant = (dataSource == null ? void 0 : dataSource.variant) || [];
  const selectorValue = import_store.default.getState().selectorValue;
  const currentSkuId = `${sku == null ? void 0 : sku.variant_group_id}:${sku == null ? void 0 : sku.id}`;
  const selectedVariantIds = [currentSkuId];
  (_a = dataSource == null ? void 0 : dataSource.variant_group) == null ? void 0 : _a.forEach((group) => {
    var _a2;
    const _selectedData = (_a2 = selectorValue == null ? void 0 : selectorValue[group.id]) == null ? void 0 : _a2.data;
    if (_selectedData && group.id !== (sku == null ? void 0 : sku.variant_group_id)) {
      selectedVariantIds.push(
        `${_selectedData == null ? void 0 : _selectedData.variant_group_id}:${_selectedData == null ? void 0 : _selectedData.id}`
      );
    }
  });
  const filteredVariant = variant.filter((item) => {
    var _a2;
    const ids = ((_a2 = item == null ? void 0 : item.sku_ids) == null ? void 0 : _a2.split("_")) || [];
    return selectedVariantIds.every(
      (selectedId) => ids.includes(selectedId)
    );
  });
  const _canSellResult = [];
  const _hasStockResult = [];
  filteredVariant.forEach((item) => {
    const { canSell, hasStock } = checkSkuStockCanSell(item);
    _canSellResult.push(canSell);
    _hasStockResult.push(hasStock);
  });
  return {
    // 只要有一个匹配商品能售卖，则该选项可选
    canSell: _canSellResult.some((item) => item === true),
    // 只要有一个存在库存则为true
    hasStock: _hasStockResult.some((item) => item === true)
  };
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  checkSkuDisabled,
  checkSkuStockCanSell,
  checkVariantStockByValue,
  checkVariantStockCanSell
});
