import { system, world, EquipmentSlot } from "@minecraft/server";
import { getItemInSlot } from "../../helper/utils";
import { emitDynamicLight } from "../../helper/emitDynamicLight";
export class DynamicLightItem {
    // Constructor to initialize the DynamicLightItem class
    constructor(config) {
        this.config = config;
    }
    // Register the dynamic light behavior
    static registerBehavior(config) {
        const dynamicLightBehavior = new DynamicLightItem(config);
        DynamicLightItem.items.push(dynamicLightBehavior);
    }
    // Initialize the dynamic lighting system (runs periodically to check player's held items)
    static initialize() {
        system.runInterval(() => {
            const players = world.getPlayers();
            players.forEach((player) => {
                const itemStack = getItemInSlot(player, EquipmentSlot.Mainhand);
                if (!itemStack)
                    return;
                const dynamicLightItem = DynamicLightItem.getItem(itemStack?.typeId);
                if (dynamicLightItem) {
                    emitDynamicLight(dynamicLightItem.config.strength, player);
                }
            });
        }, 1); // Check every tick (20 times per second)
    }
    // Helper method to get the DynamicLightItem by item identifier
    static getItem(itemId) {
        return this.items.find((item) => item.config.id === itemId);
    }
}
DynamicLightItem.items = [];
