import { Player } from "@minecraft/server";
import { ActionFormData } from "@minecraft/server-ui";

/**
 * 
 * @param {Player} player 
 */
export function guideBook(player) {
    const form = new ActionFormData()
        .title({ translate: `translate.cy_cr_guide_book.title` })
        .body({ translate: `translate.cy_cr_guide_book.body` })
        .button({ translate: `translate.cy_cr_guide_book.ingredients` }, `textures/cy/cr/items/dryer`)
        .button({ translate: `translate.cy_cr_guide_book.factories` }, `textures/cy/cr/items/wheat_farm`)
        .button({ translate: `translate.cy_cr_guide_book.factories` }, `textures/cy/cr/items/guide_book`);
    form.show(player).then((result) => {
        if (result.selection === 0) {
            ingredients(player)
        } else if (result.selection === 1) {
            factories(player)
        } else if (result.selection === 2) {
            objectDesc(player, `item.cy_cr:guide_book`, `translate.cy_cr.guide_book.guide_book`)
        }
    })
};
/**
 * 
 * @param {Player} player 
 * * @param {String} title
 * @param {String} description
 */
function objectDesc(player, title, description) {
    const form = new ActionFormData()
        .title({ translate: title })
        .body({ translate: description })
        .button({ translate: `translate.cy_cr.guide_book.back` })
    form.show(player).then(result => {
        if (result.selection === 0) {
            if (title.includes(`item`)) {
                ingredients(player)
            } else if (title.includes(`entity`)) {
                factories(player)
            }
        }
    })
}
/**
 * 
 * @param {Player} player 
 */
function ingredients(player) {
    const form = new ActionFormData()
        .title({ translate: `translate.cy_cr_guide_book.ingredients` })
        .body({ translate: `translate.cy_cr.guide_book.ingredients_body` })
        .button({ translate: `translate.item.cy_cr:engine_command` }, `textures/cy/cr/ui/engine_command`)
        .button({ translate: `translate.item.cy_cr:wireless_engine_command` }, `textures/cy/cr/ui/wireless_engine_command`)
        .button({ translate: `translate.item.cy_cr:ec_chest` }, `textures/cy/cr/ui/ec_chest`)
        .button({ translate: `translate.item.cy_cr:ec_cauldron` }, `textures/cy/cr/ui/ec_cauldron`)
        .button({ translate: `translate.item.cy_cr:sponge_circle` }, `textures/cy/cr/ui/sponge_circle`)
        .button({ translate: `translate.item.cy_cr:fan` }, `textures/cy/cr/ui/fan`)
        .button({ translate: `translate.item.cy_cr:dryer` }, `textures/cy/cr/ui/dryer`)
        .button({ translate: `translate.item.cy_cr:feeder` }, `textures/cy/cr/ui/feeder`)
        .button({ translate: `translate.item.cy_cr:glass_cube` }, `textures/cy/cr/ui/glass_cube`)
        .button({ translate: `translate.item.cy_cr:moving_target` }, `textures/cy/cr/ui/moving_target`)
        .button({ translate: `translate.item.cy_cr:projector` }, `textures/cy/cr/ui/projector`)
        .button({ translate: `translate.item.cy_cr:redstone_arm` }, `textures/cy/cr/ui/redstone_arm`)
        .button({ translate: `translate.item.cy_cr:redstone_claw` }, `textures/cy/cr/ui/redstone_claw`)
        .button({ translate: `translate.item.cy_cr:ra_claw` }, `textures/cy/cr/ui/ra_claw`)
        .button({ translate: `translate.item.cy_cr:ra_saw` }, `textures/cy/cr/ui/ra_saw`)
        .button({ translate: `translate.item.cy_cr:ra_hopper` }, `textures/cy/cr/ui/ra_hopper`)
        .button({ translate: `translate.item.cy_cr:turbine` }, `textures/cy/cr/ui/turbine`)
        .button({ translate: `translate.cy_cr.guide_book.back` })
    form.show(player).then(result => {
        if (result.canceled === false) {
            if (result.selection === 17) {
                guideBook(player)
            } else {
                const list = ["engine_command", "wireless_engine_command", "ec_chest", "ec_cauldron", "sponge_circle", "fan", "dryer", "feeder", "glass_cube", "moving_target", "projector", "redstone_arm", "redstone_claw", "ra_claw", "ra_saw", "ra_hopper", "turbine"];
                const text = `translate.cy_cr.guide_book.`;
                const text2 = `translate.item.cy_cr:`;
                const description = `${text}${list[result.selection]}`;
                const title = `${text2}${list[result.selection]}`;
                objectDesc(player, title, description)
            }
        }
    })
};
/**
 * 
 * @param {Player} player 
 */
function factories(player) {
    const form = new ActionFormData()
        .title({ translate: `translate.cy_cr_guide_book.factories` })
        .body({ translate: `translate.cy_cr.guide_book.factories_body` })
        .button({ translate: `translate.entity.cy_cr:redstone_capsule` }, `textures/cy/cr/ui/capsule`)
        .button({ translate: `translate.entity.cy_cr:antirain_station` }, `textures/cy/cr/ui/antirain_station`)
        .button({ translate: `translate.entity.cy_cr:eggs_farm` }, `textures/cy/cr/ui/eggs_farm`)
        .button({ translate: `translate.entity.cy_cr:arrow_farm` }, `textures/cy/cr/ui/arrow_farm`)
        .button({ translate: `translate.entity.cy_cr:potion_farm` }, `textures/cy/cr/ui/potion_farm`)
        .button({ translate: `translate.entity.cy_cr:string_farm` }, `textures/cy/cr/ui/string_farm`)
        .button({ translate: `translate.entity.cy_cr:tear_farm` }, `textures/cy/cr/ui/tear_farm`)
        .button({ translate: `translate.entity.cy_cr:cobble_factory` }, `textures/cy/cr/ui/cobble_factory`)
        .button({ translate: `translate.entity.cy_cr:wood_factory` }, `textures/cy/cr/ui/wood_factory`)
        .button({ translate: `translate.entity.cy_cr:wheat_farm` }, `textures/cy/cr/ui/wheat_farm`)
        .button({ translate: `translate.entity.cy_cr:beetroot_farm` }, `textures/cy/cr/ui/beetroot_farm`)
        .button({ translate: `translate.entity.cy_cr:carrot_farm` }, `textures/cy/cr/ui/carrot_farm`)
        .button({ translate: `translate.entity.cy_cr:potato_farm` }, `textures/cy/cr/ui/potato_farm`)
        .button({ translate: `translate.entity.cy_cr:berry_farm` }, `textures/cy/cr/ui/berry_farm`)
        .button({ translate: `translate.entity.cy_cr:sugar_farm` }, `textures/cy/cr/ui/sugar_farm`)
        .button({ translate: `translate.entity.cy_cr:netherwart_farm` }, `textures/cy/cr/ui/netherwart_farm`)
        .button({ translate: `translate.entity.cy_cr:milk_farm` }, `textures/cy/cr/ui/milk`)
        .button({translate: `translate.entity.cy_cr:cake_farm`}, `textures/cy/cr/ui/cake_farm`)
        .button({ translate: `translate.entity.cy_cr:drill` }, `textures/cy/cr/ui/drill`)
        .button({ translate: `translate.entity.cy_cr:cannon` }, `textures/cy/cr/ui/cannon`)
        .button({ translate: `translate.entity.cy_cr:turret` }, `textures/cy/cr/ui/turret`)
        .button({ translate: `translate.entity.cy_cr:trap` }, `textures/cy/cr/ui/trap`)
        .button({ translate: `translate.entity.cy_cr:charge_station` }, `textures/cy/cr/ui/redstone_golem`)
        .button({ translate: `translate.entity.cy_cr:bin` }, `textures/cy/cr/ui/bin`)
        .button({ translate: `translate.entity.cy_cr:propulser` }, `textures/cy/cr/ui/propulser`)
        .button({translate: `translate.entity.cy_cr:furnace`}, `textures/cy/cr/ui/furnace`)
        .button({ translate: `translate.entity.cy_cr:small_door` }, `textures/cy/cr/ui/small_door`)
        .button({ translate: `translate.entity.cy_cr:small_door_wireless` }, `textures/cy/cr/ui/small_door_wireless`)
        .button({ translate: `translate.entity.cy_cr:medium_door` }, `textures/cy/cr/ui/medium_door`)
        .button({ translate: `translate.entity.cy_cr:medium_door_wireless` }, `textures/cy/cr/ui/medium_door_wireless`)
        .button({ translate: `translate.entity.cy_cr:big_door` }, `textures/cy/cr/ui/big_door`)
        .button({ translate: `translate.entity.cy_cr:big_door_wireless` }, `textures/cy/cr/ui/big_door_wireless`)
        .button({ translate: `translate.entity.cy_cr:item_conveyor` }, `textures/cy/cr/ui/item_conveyor`)
        .button({ translate: `translate.cy_cr.guide_book.back` });
    form.show(player).then(result => {
        if (result.canceled === false) {
            if (result.selection === 33) {
                guideBook(player)
            } else {
                const list = ["redstone_capsule", "antirain_station", "eggs_farm", "arrow_farm", "potion_farm", "string_farm", "tear_farm", "cobble_factory", "wood_factory", "wheat_farm", "beetroot_farm", "carrot_farm", "potato_farm", "berry_farm", "sugar_farm", "netherwart_farm", "milk_farm", "cake_farm", "drill", "cannon", "turret", "trap", "charge_station", "bin", "propulser", "furnace", "small_door", "small_door_wireless", "medium_door", "medium_door_wireless", "big_door", "big_door_wireless", "item_conveyor"];
                const text = `translate.cy_cr.guide_book.`;
                const text2 = `translate.entity.cy_cr:`;
                const description = `${text}${list[result.selection]}`;
                const title = `${text2}${list[result.selection]}`;
                objectDesc(player, title, description)
            }
        }
    })
}