import { world } from "@minecraft/server";
import { spawnEggStatTypes } from "../DATA/Config";
export function incubator(log) {
    let dimensions = [];
    world.getAllPlayers().forEach((player) => {
        const dimension = player.dimension;
        if (!dimensions.includes(dimension)) {
            dimensions.push(dimension);
        }
    });
    const objective = world.scoreboard.getObjective("kicu_mmad_IncubatorTimer");
    dimensions.forEach((dimension) => {
        const incubators = dimension.getEntities({ type: "kicu_mmad:egg_incubator" });
        incubators.forEach((incubator) => {
            const eggType = incubator.getProperty("kicu_mmad:egg_type");
            if (eggType != 0) {
                const incubatorIdentity = incubator.scoreboardIdentity;
                if (!incubatorIdentity || !objective.getParticipants().includes(incubatorIdentity)) {
                    objective.setScore(incubator, 60);
                }
                if (objective.getScore(incubator) <= 0) {
                    if (incubator.getProperty("kicu_mmad:egg_ready") === false) {
                        incubator.setProperty("kicu_mmad:egg_ready", true);
                        incubator.triggerEvent("kicu_mmad:set_egg_ready_true");
                    }
                }
            }
        });
    });
    objective.getParticipants().forEach((participant) => {
        objective.addScore(participant, -1);
    });
}
export function incubatorClick(log, entity) {
    const eggType = entity.getProperty("kicu_mmad:egg_type");
    if (eggType > 0) {
        const objective = world.scoreboard.getObjective("kicu_mmad_IncubatorTimer");
        const incubatorIdentity = entity.scoreboardIdentity;
        const player = entity.dimension.getPlayers({ location: entity.location, closest: 1 })[0];
        if (incubatorIdentity && objective.getParticipants().includes(incubatorIdentity)) {
            const eggTimerMinutes = objective.getScore(incubatorIdentity) ?? 60;
            if (eggTimerMinutes > 54) {
                player.onScreenDisplay.setActionBar({
                    rawtext: [{ translate: "dialog.kicu_mmad.eggtimer.5", with: ["\n"] }],
                });
            }
            else if (eggTimerMinutes > 42) {
                player.onScreenDisplay.setActionBar({
                    rawtext: [{ translate: "dialog.kicu_mmad.eggtimer.4", with: ["\n"] }],
                });
            }
            else if (eggTimerMinutes > 30) {
                player.onScreenDisplay.setActionBar({
                    rawtext: [{ translate: "dialog.kicu_mmad.eggtimer.3", with: ["\n"] }],
                });
            }
            else if (eggTimerMinutes > 18) {
                player.onScreenDisplay.setActionBar({
                    rawtext: [{ translate: "dialog.kicu_mmad.eggtimer.2", with: ["\n"] }],
                });
            }
            else if (eggTimerMinutes > 12) {
                player.onScreenDisplay.setActionBar({
                    rawtext: [{ translate: "dialog.kicu_mmad.eggtimer.1", with: ["\n"] }],
                });
            }
            else if (eggTimerMinutes > 0) {
                player.onScreenDisplay.setActionBar({
                    rawtext: [{ translate: "dialog.kicu_mmad.eggtimer.0", with: ["\n"] }],
                });
            }
            else {
                const eggType = entity.getProperty("kicu_mmad:egg_type");
                if (eggType in spawnEggStatTypes) {
                    const eggData = spawnEggStatTypes[eggType];
                    entity.setProperty("kicu_mmad:egg_type", 0);
                    world.scoreboard.getObjective("kicu_mmad:jig_computer.addon_stats")?.addScore(eggData.eggStat, 1);
                    player.runCommand(`give @s ${eggData.eggHatchSpawnEgg}`);
                    player.playSound("sound.kicu_mmad_pick_up_egg");
                    objective.removeParticipant(incubatorIdentity);
                    entity.setProperty("kicu_mmad:egg_ready", false);
                }
            }
        }
    }
}

//# sourceMappingURL=../../../../../_KiCuMountsBPDebug/kicu/mmad/C/Incubator.js.map
