import * as utils from "../utils/index";
import { CompanionCombatSupportComponent } from "./components/index";
import { DefaultTask, GoDiggingTask, GoMiningTask, GoLoggingTask, GoLightingTask, DespawnTask, CostumeChangeTask } from "./tasks/index";
import { Achievement } from "../achievements/index";
export const INTERACT_MENU = {
    main: new utils.ButtonMenu({ translate: "ldz_crcomp:craftee.interact.name" }, [
        {
            text: { translate: "ldz_crcomp:craftee.idle.button" },
            texture: "textures/blocks/barrier",
            onClick(player, companion) {
                var _a;
                companion.broadcastEvent("interrupt");
                (_a = companion.CurrentTask) === null || _a === void 0 ? void 0 : _a.abort();
            },
            shouldHide(player, companion) {
                return companion.CurrentTask instanceof DefaultTask;
            },
        },
        {
            text: { translate: "ldz_crcomp:craftee.dig.button" },
            texture: "textures/items/stone_shovel",
            onClick(player, companion) {
                companion.startTask(new GoDiggingTask(companion), true);
            },
            shouldHide(player, companion) {
                return companion.CurrentTask instanceof GoDiggingTask;
            },
        },
        {
            text: { translate: "ldz_crcomp:craftee.mine.button" },
            texture: "textures/items/stone_pickaxe",
            onClick(player, companion) {
                companion.startTask(new GoMiningTask(companion), true);
            },
            shouldHide(player, companion) {
                return companion.CurrentTask instanceof GoMiningTask;
            },
        },
        {
            text: { translate: "ldz_crcomp:craftee.log.button" },
            texture: "textures/items/stone_axe",
            onClick(player, companion) {
                companion.startTask(new GoLoggingTask(companion), true);
            },
            shouldHide(player, companion) {
                return companion.CurrentTask instanceof GoLoggingTask;
            },
        },
        {
            text(player, companion) {
                if (companion.getComponent(CompanionCombatSupportComponent)) {
                    return { translate: "ldz_crcomp:craftee.stop_support.button" };
                }
                else {
                    return { translate: "ldz_crcomp:craftee.start_support.button" };
                }
            },
            texture: "textures/items/stone_sword",
            onClick(player, companion) {
                if (companion.getComponent(CompanionCombatSupportComponent)) {
                    companion.removeComponent(CompanionCombatSupportComponent.ComponentId);
                }
                else {
                    companion.addComponent(new CompanionCombatSupportComponent());
                }
            },
        },
        {
            text: { translate: "ldz_crcomp:craftee.light.button" },
            texture: "textures/ldz/crcomp/ui_icons/torch",
            onClick(player, companion) {
                companion.startTask(new GoLightingTask(companion), true);
            },
            shouldHide(player, companion) {
                return companion.CurrentTask instanceof GoLightingTask;
            },
        },
        {
            text: { translate: "ldz_crcomp:craftee.give.button" },
            texture: "textures/ui/icon_blackfriday",
            onClick(player, companion) {
                var _a;
                (_a = companion.VirtualInventory) === null || _a === void 0 ? void 0 : _a.transferItems(player);
            },
            shouldHide(player, companion) {
                var _a;
                return !Boolean((_a = companion.VirtualInventory) === null || _a === void 0 ? void 0 : _a.Count);
            },
        },
        {
            text: { translate: "ldz_crcomp:craftee.quest_request.button" },
            texture: "textures/ldz/crcomp/ui_icons/quest_details",
            onClick(player, companion) {
                var _a;
                (_a = companion.Quest) === null || _a === void 0 ? void 0 : _a.setNewQuest();
            },
            shouldHide(player, companion) {
                var _a;
                return ((_a = companion.Quest) === null || _a === void 0 ? void 0 : _a.QuestStatus) !== "none";
            },
        },
        {
            text: { translate: "ldz_crcomp:craftee.quest_details.button" },
            texture: "textures/ldz/crcomp/ui_icons/quest_details",
            onClick(player, companion) {
                INTERACT_MENU.questDetails.showMenuToPlayer(player, companion, 0);
            },
            shouldHide(player, companion) {
                var _a;
                return ((_a = companion.Quest) === null || _a === void 0 ? void 0 : _a.QuestStatus) !== "pending";
            },
        },
        {
            text: { translate: "ldz_crcomp:craftee.quest_reward.button" },
            texture: "textures/ldz/crcomp/ui_icons/quest_reward",
            onClick(player, companion) {
                var _a;
                (_a = companion.Quest) === null || _a === void 0 ? void 0 : _a.completeQuest();
            },
            shouldHide(player, companion) {
                var _a;
                return ((_a = companion.Quest) === null || _a === void 0 ? void 0 : _a.QuestStatus) !== "completed";
            },
        },
        {
            text: { translate: "ldz_crcomp:craftee.cosmetics.button" },
            texture: "textures/ui/icon_hangar",
            onClick(player, companion) {
                INTERACT_MENU.cosmetics.showMenuToPlayer(player, companion, 0);
            },
        },
        {
            text: { translate: "ldz_crcomp:craftee.achievements.button" },
            texture: "textures/ldz/crcomp/ui_icons/trophy",
            onClick(player, companion) {
                INTERACT_MENU.achievements.showMenuToPlayer(player, companion, 0);
            },
        },
        {
            text: { translate: "ldz_crcomp:craftee.overview.button" },
            texture: "textures/ui/infobulb",
            onClick(player, companion) {
                INTERACT_MENU.overview.showMenuToPlayer(player, companion, 0);
            },
        },
        {
            text: { translate: "ldz_crcomp:craftee.despawn.button" },
            texture: "textures/ldz/crcomp/items/craftee_spawnegg",
            onClick(player, companion) {
                companion.globalStopSound();
                companion.Owner.playSound('ldz_crcomp:craftee.despawn_warning.0', { volume: companion.Volume });
                INTERACT_MENU.despawn.showMenuToPlayer(player, companion, 0);
            },
        },
    ], (player, companion, messageIndex) => { return { translate: `ldz_crcomp:craftee.interact.${messageIndex}` }; }),
    deathMenu: new utils.ButtonMenu({ translate: "ldz_crcomp:craftee.interact.name" }, [
        {
            text: { translate: "ldz_crcomp:craftee.despawn.button" },
            texture: "textures/ldz/crcomp/items/craftee_spawnegg",
            onClick(player, companion) {
                companion.globalStopSound();
                companion.Owner.playSound('ldz_crcomp:craftee.despawn_warning.0', { volume: companion.Volume });
                INTERACT_MENU.despawn.showMenuToPlayer(player, companion, 0);
            },
        },
    ], (player, companion, messageIndex) => { return { translate: `ldz_crcomp:craftee.interact.${messageIndex}` }; }),
    questDetails: new utils.ButtonMenu({ translate: "ldz_crcomp:craftee.quest_details.button" }, [
        {
            text: { translate: "ldz_crcomp:craftee.quest_details.cancel" },
            texture: "textures/ldz/crcomp/ui_icons/cancel_quest",
            onClick(player, companion) {
                var _a;
                player.runCommand('function ldz/crcomp/global_stopsound');
                companion.broadcastEvent("interrupt");
                (_a = companion.Quest) === null || _a === void 0 ? void 0 : _a.clearQuest();
            },
        },
        {
            text: { translate: "ldz_crcomp:craftee.back.button" },
            texture: "textures/ldz/crcomp/ui_icons/back",
            onClick(player, params_0, params_1) {
                INTERACT_MENU.main.showMenuToPlayer(player, params_0, params_1);
                player.runCommand('function ldz/crcomp/global_stopsound');
                params_0.broadcastEvent("interrupt");
            },
        },
    ], (player, companion) => { var _a, _b; return (_b = (_a = companion.Quest) === null || _a === void 0 ? void 0 : _a.QuestDetails) !== null && _b !== void 0 ? _b : ""; }).onCancel((player, cancelationReason, companion, val) => player.runCommand('function ldz/crcomp/global_stopsound')),
    cosmetics: new utils.ModalMenu({ translate: "ldz_crcomp:craftee.cosmetics.button" }, [
        {
            type: "toggle",
            text: { translate: "ldz_crcomp:craftee.cosmetics.hat" },
            defaultValue(player, params_0, params_1) {
                return Boolean(params_0.Entity.getProperty("hide_hat"));
            },
            onSubmit(player, toggleValue, params_0, params_1) {
                params_0.Entity.setProperty("hide_hat", toggleValue);
            },
        },
        {
            type: "dropdown",
            text: { translate: "ldz_crcomp:craftee.cosmetics.costume" },
            defaultValueIndex(player, params_0, params_1) {
                const achievementList = Object.values(Achievement.Achievements).filter(achievement => achievement.getStatus(player));
                for (let index = 0; index < achievementList.length; index++) {
                    const achievement = achievementList[index];
                    if (achievement.SkinIndex === params_0.Entity.getProperty("costume")) {
                        return index + 1; // Add one to offset for classic skin option
                    }
                }
                return 0;
            },
            options: [
                {
                    text: { rawtext: [{ translate: `ldz_crcomp:craftee.achievement.default.title.dropdown` }] },
                    onSelected(player, params_0, params_1) {
                        params_0.startTask(new CostumeChangeTask(params_0, { costumeId: 0 }), true);
                    },
                },
                ...Object.values(Achievement.Achievements).map(achievement => achievement.getDropdownOption())
            ],
        }
    ], { translate: "ldz_crcomp:craftee.confirm" }),
    achievements: new utils.ButtonMenu({ translate: "ldz_crcomp:craftee.achievements.button" }, [
        {
            text: { translate: "ldz_crcomp:craftee.back.button" },
            texture: "textures/ldz/crcomp/ui_icons/back",
            onClick(player, params_0, params_1) {
                INTERACT_MENU.main.showMenuToPlayer(player, params_0, params_1);
            },
        },
    ], (player, companion, index) => { return { rawtext: Object.values(Achievement.Achievements).map(achievement => achievement.getStatusText(player)) }; }),
    overview: new utils.ButtonMenu({ translate: "ldz_crcomp:craftee.overview.button" }, [
        {
            text: { translate: "ldz_crcomp:craftee.about.button" },
            texture: "textures/ldz/crcomp/ui_icons/infobulb",
            onClick(player, companion) {
                player.playSound(`ldz_crcomp:craftee.interact.4`, { volume: companion.Volume });
                INTERACT_MENU.about.showMenuToPlayer(player, companion, 0);
            },
        },
        {
            text: { translate: "ldz_crcomp:craftee.patch_notes.button" },
            texture: "textures/ldz/crcomp/ui_icons/update_icon",
            onClick(player, companion) {
                INTERACT_MENU.patch_notes.showMenuToPlayer(player, companion, 0);
            },
        },
        {
            text: { translate: "ldz_crcomp:craftee.settings.button" },
            texture: "textures/ldz/crcomp/ui_icons/settings",
            onClick(player, companion) {
                INTERACT_MENU.settings.showMenuToPlayer(player, companion, 0);
            },
        },
        {
            text: { translate: "ldz_crcomp:craftee.credits.button" },
            texture: "textures/ldz/crcomp/ui_icons/credits",
            onClick(player, companion) {
                INTERACT_MENU.credits.showMenuToPlayer(player, companion, 0);
            },
        },
        {
            text: { translate: "ldz_crcomp:craftee.back.button" },
            texture: "textures/ldz/crcomp/ui_icons/back",
            onClick(player, companion) {
                INTERACT_MENU.main.showMenuToPlayer(player, companion, 0);
            },
        },
    ]),
    about: new utils.ButtonMenu({ translate: "ldz_crcomp:craftee.about.title" }, [
        {
            text: { translate: "ldz_crcomp:craftee.back.button" },
            texture: "textures/ldz/crcomp/ui_icons/back",
            onClick(player, params_0, params_1) {
                INTERACT_MENU.overview.showMenuToPlayer(player, params_0, params_1);
            },
        },
    ], { translate: "ldz_crcomp:craftee.about.body", with: ["\n"] }),
    patch_notes: new utils.ButtonMenu(() => ({ translate: "ldz_crcomp:update.version.name", with: [utils.getVersionNumber()] }), [
        {
            text: { translate: "ldz_crcomp:craftee.back.button" },
            texture: "textures/ldz/crcomp/ui_icons/back",
            onClick(player, params_0, params_1) {
                INTERACT_MENU.overview.showMenuToPlayer(player, params_0, params_1);
            },
        },
    ], { translate: "ldz_crcomp:craftee.patch_notes.body", with: ["\n"] }),
    credits: new utils.ButtonMenu(() => ({ translate: "ldz_crcomp:update.version.name", with: [utils.getVersionNumber()] }), [
        {
            text: { translate: "ldz_crcomp:craftee.back.button" },
            texture: "textures/ldz/crcomp/ui_icons/back",
            onClick(player, params_0, params_1) {
                INTERACT_MENU.overview.showMenuToPlayer(player, params_0, params_1);
            },
        },
    ], { translate: "ldz_crcomp:craftee.credits.body", with: ["\n"] }),
    settings: new utils.ModalMenu({ translate: "ldz_crcomp:craftee.settings.button" }, [
        {
            type: "slider",
            text: { translate: "ldz_crcomp:craftee.settings.audio" },
            minimumValue: 0,
            maximumValue: 100,
            valueStep: 5,
            defaultValue(player, companion) {
                return companion.Volume * 100;
            },
            onSubmit(player, sliderValue, companion) {
                var _a;
                companion.Volume = sliderValue / 100;
                (_a = companion.Dialogue) === null || _a === void 0 ? void 0 : _a.addDialogueToQueue(player, "interrupt");
            },
        },
        {
            type: "toggle",
            text: { translate: "ldz_crcomp:craftee.settings.hat_notify" },
            defaultValue(player, params_0, params_1) {
                var _a;
                return (_a = utils.readDynamicProperty(player, "settings.hat_notify")) !== null && _a !== void 0 ? _a : true;
            },
            onSubmit(player, toggleValue, params_0, params_1) {
                utils.writeDynamicProperty(player, "settings.hat_notify", toggleValue);
            },
        },
        {
            type: "toggle",
            text: { translate: "ldz_crcomp:craftee.settings.hat_spawn" },
            defaultValue(player, params_0, params_1) {
                var _a;
                return (_a = utils.readDynamicProperty(player, "settings.hat_spawn")) !== null && _a !== void 0 ? _a : true;
            },
            onSubmit(player, toggleValue, params_0, params_1) {
                utils.writeDynamicProperty(player, "settings.hat_spawn", toggleValue);
            },
        },
    ], { translate: "ldz_crcomp:craftee.confirm" }),
    despawn: new utils.ButtonMenu({ translate: "ldz_crcomp:craftee.interact.name" }, [
        {
            text: { translate: 'ldz_crcomp:craftee.despawn.accept' },
            onClick(player, companion) {
                companion.startTask(new DespawnTask(companion, { player }), true);
            },
        },
        {
            text: { translate: 'ldz_crcomp:craftee.despawn.reject' },
            onClick(player, companion) {
                companion.broadcastEvent("interrupt");
            },
        }
    ], { translate: "ldz_crcomp:craftee.despawn.warning", with: ["\n"] }),
};
export const NON_OWNER_MENU = new utils.ButtonMenu({ translate: "ldz_crcomp:craftee.interact.name" }, [
    {
        text: { translate: "ldz_crcomp:craftee.despawn.button" },
        texture: "textures/ldz/crcomp/items/craftee_spawnegg",
        onClick(player, companion) {
            companion.globalStopSound();
            companion.Owner.playSound('ldz_crcomp:craftee.despawn_warning.0', { volume: companion.Volume });
            INTERACT_MENU.despawn.showMenuToPlayer(player, companion, 0);
        },
    }
], (player, companion, messageIndex) => { return { translate: `ldz_crcomp:craftee.interact.${messageIndex}` }; });
