"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 ModelTreePosition_exports = {};
__export(ModelTreePosition_exports, {
  ModelTreePosition: () => ModelTreePosition
});
module.exports = __toCommonJS(ModelTreePosition_exports);
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
class ModelTreePosition {
  #owner;
  #parent;
  #root;
  constructor(owner) {
    this.#owner = owner;
  }
  get parent() {
    return this.#parent;
  }
  get root() {
    return this.#root;
  }
  /**
   * Adopt a child into this owner's tree.  Removes from previous parent if necessary.
   */
  adopt(child) {
    const childPos = child.treePosition;
    if (childPos.#parent === this.#owner) {
      return;
    }
    if (childPos.#parent) {
      const position = childPos.#parent.children.indexOf(child);
      if (position !== -1) {
        childPos.#parent.children.splice(position, 1);
      }
    }
    childPos.#parent = this.#owner;
  }
  /**
   * Update the root reference for a child.  Returns true if the root changed.
   */
  reroot(child, sharesRoot) {
    const root = sharesRoot ? this.#owner.root : void 0;
    const childPos = child.treePosition;
    if (childPos.#root === root) {
      return false;
    }
    childPos.#root = root;
    return true;
  }
  /**
   * Disown a child from this owner.  Returns true if the child was actually owned.
   */
  disown(child) {
    const childPos = child.treePosition;
    if (childPos.#parent === this.#owner) {
      childPos.#parent = void 0;
      return true;
    }
    return false;
  }
}
//# sourceMappingURL=ModelTreePosition.js.map
