var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/plus/pisellGlobalSearch/utils/detailRefresh.ts
var detailRefresh_exports = {};
__export(detailRefresh_exports, {
  buildDetailRefreshKey: () => buildDetailRefreshKey,
  buildOrderDetailRefreshFingerprints: () => buildOrderDetailRefreshFingerprints,
  bumpOrderDetailRefreshVersions: () => bumpOrderDetailRefreshVersions,
  getDetailRefreshVersion: () => getDetailRefreshVersion
});
module.exports = __toCommonJS(detailRefresh_exports);
function buildDetailRefreshKey(providerKey, id) {
  return `${providerKey}:${id}`;
}
function getDetailRefreshVersion(versions, providerKey, id) {
  if (id === void 0 || id === null || id === "") return 0;
  return versions[buildDetailRefreshKey(providerKey, id)] ?? 0;
}
function bumpOrderDetailRefreshVersions(prev, deltaItems) {
  if (!Array.isArray(deltaItems) || deltaItems.length === 0) return prev;
  let next = null;
  const bumpedKeys = /* @__PURE__ */ new Set();
  for (const item of deltaItems) {
    const id = getOrderRealtimeId(item);
    if (id == null) continue;
    const key = buildDetailRefreshKey("order", id);
    if (bumpedKeys.has(key)) continue;
    bumpedKeys.add(key);
    if (next == null) next = { ...prev };
    next[key] = (next[key] ?? 0) + 1;
  }
  return next ?? prev;
}
function buildOrderDetailRefreshFingerprints(deltaItems) {
  if (!Array.isArray(deltaItems) || deltaItems.length === 0) return {};
  return deltaItems.reduce((acc, item) => {
    const id = getOrderRealtimeId(item);
    if (id == null) return acc;
    acc[String(id)] = stableStringify(item);
    return acc;
  }, {});
}
function getOrderRealtimeId(item) {
  if (!item || typeof item !== "object") return null;
  const obj = item;
  const raw = obj.order_id ?? obj.id ?? obj.key;
  if (raw === void 0 || raw === null || raw === "") return null;
  if (typeof raw === "string" || typeof raw === "number") return raw;
  return String(raw);
}
function stableStringify(value) {
  if (Array.isArray(value)) {
    return `[${value.map(stableStringify).join(",")}]`;
  }
  if (!value || typeof value !== "object") {
    return JSON.stringify(value);
  }
  const obj = value;
  return `{${Object.keys(obj).sort().map((key) => `${JSON.stringify(key)}:${stableStringify(obj[key])}`).join(",")}}`;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  buildDetailRefreshKey,
  buildOrderDetailRefreshFingerprints,
  bumpOrderDetailRefreshVersions,
  getDetailRefreshVersion
});
