"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var import_node_test = __toESM(require("node:test"));
var import_strict = __toESM(require("node:assert/strict"));
var THREE = __toESM(require("three"));
var import_node_path = __toESM(require("node:path"));
var import_node_url = require("node:url");
var import_promises = require("node:fs/promises");
var import_boxel_core = require("@playdrop/boxel-core");
var import_instantiate = require("../src/instantiate.js");
const import_meta = {};
const HERE = import_node_path.default.dirname((0, import_node_url.fileURLToPath)(import_meta.url));
const fixture = (...segments) => import_node_path.default.resolve(HERE, "./fixtures", ...segments);
async function loadEntity(relativePath) {
  const raw = await (0, import_promises.readFile)(fixture(relativePath), "utf-8");
  return (0, import_boxel_core.parseBoxel)(JSON.parse(raw));
}
function dispose(result) {
  result.dispose();
}
(0, import_node_test.default)("instantiateEntityObject3D hierarchy mode exposes group and node helpers", async () => {
  const entity = await loadEntity("entity-connect.json");
  const result = (0, import_instantiate.instantiateEntityObject3D)({ THREE, entity, mode: "hierarchy" });
  try {
    import_strict.default.equal(result.mode, "hierarchy");
    import_strict.default.ok(result.object instanceof THREE.Group, "hierarchy returns group");
    import_strict.default.ok(result.scene.root === result.object, "group matches scene root");
    import_strict.default.ok(typeof result.findNode === "function", "findNode helper available");
    import_strict.default.ok(result.findNode(entity.geometry.root.id), "root node resolves");
    let counted = 0;
    result.forEachNode(() => {
      counted += 1;
    });
    import_strict.default.equal(counted > 0, true, "forEachNode iterates nodes");
    import_strict.default.ok(Array.isArray(result.clips), "clips array present");
  } finally {
    dispose(result);
  }
});
(0, import_node_test.default)("instantiateEntityObject3D merged mode returns a reusable group", async () => {
  const entity = await loadEntity("entity-connect.json");
  const result = (0, import_instantiate.instantiateEntityObject3D)({ THREE, entity, mode: "merged" });
  try {
    import_strict.default.equal(result.mode, "merged");
    import_strict.default.ok(result.object instanceof THREE.Object3D, "merged returns object3D");
  } finally {
    dispose(result);
  }
});
(0, import_node_test.default)("instantiateEntityObject3D skinned mode returns skinned mesh and bone helpers", async () => {
  const entity = await loadEntity("entity-connect.json");
  const result = (0, import_instantiate.instantiateEntityObject3D)({ THREE, entity, mode: "skinned" });
  try {
    import_strict.default.equal(result.mode, "skinned");
    import_strict.default.ok(result.object instanceof THREE.SkinnedMesh, "skinned returns SkinnedMesh");
    import_strict.default.ok(result.skeleton instanceof THREE.Skeleton, "skeleton available");
    import_strict.default.ok(result.findBone(entity.geometry.root.id), "findBone resolves root");
    let boneCount = 0;
    result.forEachBone(() => {
      boneCount += 1;
    });
    import_strict.default.equal(boneCount > 0, true, "forEachBone iterates bones");
    import_strict.default.ok(Array.isArray(result.clips), "clips array present");
  } finally {
    dispose(result);
  }
});
