/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { Metatype } from "../common/index.js";
import { FieldElement } from "../elements/index.js";
import { PropertyModel } from "./PropertyModel.js";
import { ValueModel } from "./ValueModel.js";
class FieldModel extends PropertyModel {
  tag = FieldElement.Tag;
  title;
  get fabricSensitive() {
    return this.effectiveAccess.fabricSensitive;
  }
  /**
   * Fields may omit their ID.  In this case we use their index within the parent as the ID.
   */
  get effectiveId() {
    if (this.id !== void 0) {
      return this.id;
    }
    if (this.parent instanceof ValueModel) {
      const index = this.parent.children.indexOf(this);
      if (index !== -1) {
        return index;
      }
    }
  }
  /**
   * The key for bitmap fields is actually the constraint which defines the bit range.  All other datatypes use the
   * default key.
   */
  get key() {
    if (this.parent instanceof ValueModel && this.parent.effectiveMetatype === Metatype.bitmap) {
      return this.constraint.toString();
    }
    return super.key;
  }
  constructor(definition, ...children) {
    super(definition, ...children);
    this.title = definition.title;
  }
  toElement(omitResources = false, extra) {
    return super.toElement(omitResources, {
      title: this.title,
      ...extra
    });
  }
  static Tag = FieldElement.Tag;
}
FieldModel.register();
export {
  FieldModel
};
//# sourceMappingURL=FieldModel.js.map
