"use strict";
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);
var DecodedBitmap_exports = {};
__export(DecodedBitmap_exports, {
  DecodedBitmap: () => DecodedBitmap
});
module.exports = __toCommonJS(DecodedBitmap_exports);
var import_ElementTag = require("#common/ElementTag.js");
var import_feature_map_element = require("#standard/elements/feature-map.element.js");
var import_general = require("@matter/general");
/**
 * @license
 * Copyright 2022-2025 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
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 === import_ElementTag.ElementTag.Attribute && model.id === import_feature_map_element.FeatureMap.id) {
    nameGenerator = (model2) => model2.title === void 0 ? (0, import_general.camelize)(model2.name) : (0, import_general.camelize)(model2.title);
  } else {
    nameGenerator = (model2) => (0, import_general.camelize)(model2.name);
  }
  return Object.fromEntries([...fields.entries()].map(([k, v]) => [nameGenerator(k), v]));
}
//# sourceMappingURL=DecodedBitmap.js.map
