import ScriptingModule from "./scriptingModule";
import { registerBlocks } from "../config/blocks";
export class BlockBehavior {
    static register(config) {
        const { id, ...behaviorConfigs } = config;
        Object.entries(behaviorConfigs).forEach(([key, value]) => {
            if (this.registry[key]) {
                const BehaviorClass = this.registry[key];
                if (BehaviorClass && typeof BehaviorClass.registerBehavior === "function") {
                    BehaviorClass.registerBehavior({ id, ...value });
                }
                else {
                    console.error(`No registerBehavior found for block type: ${key}`);
                }
            }
        });
    }
    static registerSubclass(typeOrClass, subclass) {
        if (typeof typeOrClass === "string") {
            this.registry[typeOrClass] = subclass;
        }
        else {
            const className = typeOrClass.name.toLowerCase();
            this.registry[className] = typeOrClass;
        }
    }
    static initialize() {
        Object.entries(this.registry).forEach(([key, BehaviorClass]) => {
            if (typeof BehaviorClass.initialize === "function") {
                BehaviorClass.initialize();
            }
            else if (typeof BehaviorClass === "function") {
                new BehaviorClass();
            }
        });
    }
}
BlockBehavior.registry = {};
export default class BlockModule extends ScriptingModule {
    constructor() {
        super("BlockModule");
    }
    onInitialize() {
        registerBlocks();
    }
}
