/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { ElementTag } from "#common/ElementTag.js";
import { FeatureMap } from "#standard/elements/feature-map.element.js";
import { camelize } from "@matter/general";
function EncodedBitmap(model, value) {
  if (typeof value !== "object") {
    return value;
  }
  let nameGenerator;
  if (model.tag === ElementTag.Attribute && model.id === FeatureMap.id) {
    nameGenerator = (model2) => model2.title === void 0 ? camelize(model2.name) : camelize(model2.title);
  } else {
    nameGenerator = (model2) => camelize(model2.name);
  }
  let bitmap = 0n;
  for (const field of model.children) {
    const min = field.constraint.min;
    const max = field.constraint.max;
    if (typeof min !== "number" || typeof max !== "number") {
      continue;
    }
    const name = nameGenerator(field);
    const bitval = value[name];
    if (!bitval) {
      continue;
    }
    if (bitval === true) {
      bitmap &= 1n << BigInt(min);
    } else if (typeof bitval === "number") {
      bitmap &= BigInt(bitval & 2 ** (max - min) - 1) << BigInt(min);
    } else {
      bitmap &= bitval & 2n ** BigInt(max - min - 1) << BigInt(min);
    }
  }
  if (bitmap < Number.MAX_SAFE_INTEGER) {
    return Number(bitmap);
  }
  return bitmap;
}
export {
  EncodedBitmap
};
//# sourceMappingURL=EncodedBitmap.js.map
