import { findObjectOfType, TypeStore } from "@needle-tools/engine";
import type { Object3D } from "three";
import type { MenuController } from "./scripts/MenuController.js";

/**
 * Resolve MenuController at runtime via TypeStore (registered in generated/register_types.ts).
 * Avoids passing the class constructor from modules that may load before registration.
 */
export function findMenuController(
  context: { scene: Object3D },
): MenuController | null {
  const ctor = TypeStore.get("MenuController");
  if (!ctor) return null;

  return (
    findObjectOfType(ctor, context.scene) ??
    findObjectOfType(ctor, context as never)
  );
}
