import * as mc from "@minecraft/server";
import * as utils from "../../utils/index";
import { ComponentNPC } from "./base";
export class DebugComponent extends ComponentNPC {
    constructor() {
        super(...arguments);
        this.eventBinding = this.onDebug.bind(this);
    }
    async onComponentAdded(npc) {
        super.onComponentAdded(npc);
        mc.system.afterEvents.scriptEventReceive.subscribe(this.eventBinding, { namespaces: [utils.GlobalNamespace.NamespaceUnformatted] });
    }
    async onComponentRemoved(npc) {
        mc.system.afterEvents.scriptEventReceive.unsubscribe(this.eventBinding);
    }
    onDebug(event) {
        var _a;
        if (event.id === utils.GlobalNamespace.Namespace + "debug_npc" && this.npc) {
            utils.mclog("\n-----------------");
            utils.mclog(`type: ${this.npc.Entity.typeId}`);
            utils.mclog(`id: ${this.npc.ID}`);
            utils.mclog(`health: ${(_a = this.npc.Health) === null || _a === void 0 ? void 0 : _a.currentValue}`);
            utils.mclog(`tags: ${this.npc.Entity.getTags()}`);
            utils.mclog(`components: ${this.npc.getComponentIds()}`);
            utils.mclog(`dynamicProperties:`);
            this.npc.Entity.getDynamicPropertyIds().map(value => { var _a; return `${value}: ${(_a = this.npc) === null || _a === void 0 ? void 0 : _a.Entity.getDynamicProperty(value)}`.replace(/[\\"]/g, ''); }).forEach(value => utils.mclog(`  ${value}`));
        }
    }
}
