/**
 * @license
 * Copyright 2022-2025 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 DecodedBitmap(model, value) {
  if (typeof value === "object") {
    return value;
  }
  const fields = /* @__PURE__ */ new Map();
  if (value === 0) {
    return {};
  }
  for (let bit = 0; Math.pow(2, bit) <= value; bit++) {
    if (typeof value === "bigint") {
      if (!(value & 1n << BigInt(bit))) {
        continue;
      }
    } else if (!(value & 1 << bit)) {
      continue;
    }
    const definition = model.bitDefinition(bit);
    if (!definition) {
      continue;
    }
    const constraint = definition.effectiveConstraint;
    if (constraint.value !== void 0) {
      fields.set(definition, true);
    } else if (constraint.min !== void 0) {
      const fieldBit = 1 << bit - constraint.min;
      fields.set(definition, (fields.get(definition) ?? 0) | fieldBit);
    }
  }
  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);
  }
  return Object.fromEntries([...fields.entries()].map(([k, v]) => [nameGenerator(k), v]));
}
export {
  DecodedBitmap
};
//# sourceMappingURL=DecodedBitmap.js.map
