import * as mc from "@minecraft/server";
import * as utils from "../../utils/index";
import * as comp from "../components/index";
import { BotBase } from "../bot";
export class WeatherBot extends BotBase {
    get Climate() {
        return this.getProperty("climate");
    }
    onConstructed() {
        super.onConstructed();
        this.runCommand(`stopsound @a ldz_240927:entity.bot.power_down`);
        this.addActorComponent(comp.BlockSnapComponent, { angle: 90 });
    }
    onInteract(player) {
        player.playSound(utils.addName("menu.bot.open"));
        this.showWeatherMenu(player);
        //player.playSound(utils.addName("menu.tablet.generic"));
    }
    showWeatherMenu(player) {
        new utils.MenuBuilder({
            type: "buttons",
            title: { translate: "ldz_240927:action.menu.weather.title" },
            contents: [
                {
                    text: { translate: "ldz_240927:action.menu.weathercycle.stop" },
                    texture: "textures/ldz/240927/ui/weather_clock/weather.stop",
                    shouldHide: () => !mc.world.gameRules.doWeatherCycle,
                    onClick(player) {
                        player.playSound(utils.addName("menu.bot.confirm"));
                        player.runCommand("gamerule doweathercycle false");
                        sendMessages({ translate: "ldz_240927:action.menu.weathercycle.message", with: [player.name, "has paused"] });
                    },
                },
                {
                    text: { translate: "ldz_240927:action.menu.weathercycle.start" },
                    texture: "textures/ldz/240927/ui/weather_clock/weather.start",
                    shouldHide: () => mc.world.gameRules.doWeatherCycle,
                    onClick(player) {
                        player.playSound(utils.addName("menu.bot.confirm"));
                        player.runCommand("gamerule doweathercycle true");
                        sendMessages({ translate: "ldz_240927:action.menu.weathercycle.message", with: [player.name, "has resumed"] });
                    },
                },
                {
                    text: { translate: "ldz_240927:action.menu.weather.clear" },
                    texture: "textures/ldz/240927/ui/weather_clock/weather.clear",
                    onClick(player) {
                        player.playSound(utils.addName("menu.bot.confirm"));
                        utils.overworld.setWeather(mc.WeatherType.Clear);
                        sendMessages({ translate: "ldz_240927:action.menu.weather.message", with: [player.name, "clear skies"] });
                    },
                },
                {
                    text: () => this.Climate === "cold" ? { translate: "ldz_240927:action.menu.weather.snow" } : { translate: "ldz_240927:action.menu.weather.rain" },
                    texture: () => this.Climate === "cold" ? "textures/ldz/240927/ui/weather_clock/weather.snow" : "textures/ldz/240927/ui/weather_clock/weather.rain",
                    shouldHide: () => this.Climate === "dry",
                    onClick: (player) => {
                        player.playSound(utils.addName("menu.bot.confirm"));
                        utils.overworld.setWeather(mc.WeatherType.Rain);
                        sendMessages({ translate: "ldz_240927:action.menu.weather.message", with: [player.name, (this.Climate === "cold" ? "snowing" : "raining")] });
                    },
                },
                {
                    text: { translate: "ldz_240927:action.menu.weather.thunder" },
                    texture: "textures/ldz/240927/ui/weather_clock/weather.thunder",
                    shouldHide: () => this.Climate !== "mild",
                    onClick(player) {
                        player.playSound(utils.addName("menu.bot.confirm"));
                        utils.overworld.setWeather(mc.WeatherType.Thunder);
                        sendMessages({ translate: "ldz_240927:action.menu.weather.message", with: [player.name, "a thunderstorm"] });
                    },
                },
            ],
        }).showMenuToPlayer(player);
    }
}
function sendMessages(message) {
    utils.getAllPlayersSafe().forEach(player => player.sendMessage(message));
}
utils.Actor.makeActors({ type: "ldz_240927:weather_bot" }, WeatherBot);
