import { world } from "@minecraft/server";
import { replaySessions } from "../../data/replay-player-session";
import config from "../../data/util/config";
import { debugLog } from "../../data/util/debug";
function addBowEvent(map, playerID, event) {
    let events = map.get(playerID);
    if (!events) {
        events = [];
        map.set(playerID, events);
    }
    events.push(event);
}
function captureStartData(eventData) {
    const player = eventData.source;
    const session = replaySessions.playerSessions.get(player.id);
    if (!session || session.replayStateMachine.state !== "recPending")
        return;
    const tick = session.recordingEndTick;
    const itemStartData = {
        trackingTick: tick,
        typeId: eventData.itemStack.typeId,
        startTime: tick,
        chargeTime: 0,
        endTime: 0,
        firedAt: 0,
    };
    addBowEvent(session.playerItemUseDataMap, player.id, itemStartData);
    if (config.debugItemUseEvents === true) {
        debugLog(`[ReplayCraft DEBUG] Bow started charging: ${JSON.stringify(itemStartData)}`);
    }
}
const replayCraftItemStartAfterEvent = () => {
    world.afterEvents.itemStartUse.subscribe(captureStartData);
};
export { replayCraftItemStartAfterEvent };
