import { world, ItemStack } from '@minecraft/server';
import { ActionFormData } from '@minecraft/server-ui';

world.afterEvents.playerSpawn.subscribe(event => {
    const { player } = event;
    if (player.getDynamicProperty('compycraft_breakout:given_book')) return;
    player.dimension.spawnItem(new ItemStack('compycraft_breakout:guide_book'), player.location)
    player.setDynamicProperty('compycraft_breakout:given_book', true)
})

world.afterEvents.itemUse.subscribe(event => {
    const { itemStack, source } = event;
    if (itemStack.typeId != 'compycraft_breakout:guide_book') return;
    const form = new ActionFormData()
        .title({ translate: 'compycraft_breakout.guide_book.title' })
        .body({
            rawtext: [
                { translate: 'compycraft_breakout.guide_book.text_1' }, { text: '\n' }, { text: '\n' },
                { translate: 'compycraft_breakout.guide_book.text_2' }, { text: '\n' }, { text: '\n' },
                { translate: 'compycraft_breakout.guide_book.text_3' }, { text: '\n' }, { text: '\n' },
                { translate: 'compycraft_breakout.guide_book.text_20' }, { text: '\n' },
                { translate: 'compycraft_breakout.guide_book.text_21' }, { text: '\n' },
                { translate: 'compycraft_breakout.guide_book.text_22' }, { text: '\n' },
                { translate: 'compycraft_breakout.guide_book.text_23' }, { text: '\n' },
                { translate: 'compycraft_breakout.guide_book.text_24' }, { text: '\n' },
                { translate: 'compycraft_breakout.guide_book.text_25' }, { text: '\n' },
                { translate: 'compycraft_breakout.guide_book.text_26' }, { text: '\n' },
                { translate: 'compycraft_breakout.guide_book.text_27' }, { text: '\n' }, { text: '\n' },
                { translate: 'compycraft_breakout.guide_book.text_4' }, { text: '\n' },
                { translate: 'compycraft_breakout.guide_book.text_5' }, { text: '\n' },
                { translate: 'compycraft_breakout.guide_book.text_6' }, { text: '\n' },
                { translate: 'compycraft_breakout.guide_book.text_7' }, { text: '\n' }, { text: '\n' },
                { translate: 'compycraft_breakout.guide_book.text_8' }, { text: '\n' },
                { translate: 'compycraft_breakout.guide_book.text_9' }, { text: '\n' },
                { translate: 'compycraft_breakout.guide_book.text_10' }, { text: '\n' },
                { translate: 'compycraft_breakout.guide_book.text_11' }, { text: '\n' }, { text: '\n' },
                { translate: 'compycraft_breakout.guide_book.text_12' }, { text: '\n' },
                { translate: 'compycraft_breakout.guide_book.text_13' }, { text: '\n' },
                { translate: 'compycraft_breakout.guide_book.text_14' }, { text: '\n' },
                { translate: 'compycraft_breakout.guide_book.text_15' }, { text: '\n' }, { text: '\n' },
                { translate: 'compycraft_breakout.guide_book.text_16' }, { text: '\n' },
                { translate: 'compycraft_breakout.guide_book.text_17' }, { text: '\n' },
                { translate: 'compycraft_breakout.guide_book.text_18' }, { text: '\n' },
                { translate: 'compycraft_breakout.guide_book.text_19' }, { text: '\n' }
            ]
        })
        .button({ translate: 'compycraft_breakout.guide_book.exit' })
    form.show(source)
})