import { world } from "@minecraft/server";
import { customGlassPane } from "./customGlassPane";
import { Utils } from "./utils";
import giveASingleBook from "./util/give-a-single-book";
import { showMainMenuForm } from "./forms/mainMenuForm";

world.afterEvents.playerBreakBlock.subscribe(event => {
    const block = event.block
    glassPaneUpdate(block);
    
});

world.afterEvents.playerPlaceBlock.subscribe(event => {
    const block = event.block
    glassPaneUpdate(block);
    
});


function glassPaneUpdate(block){
    customGlassPane(block);
    const neighborBlocks = Utils.getNeighborBlocks(block);

    neighborBlocks.forEach(neighborBlock => {
        customGlassPane(neighborBlock);
    });
}

const BOOK_ID = "bps_cg:cg_book" // Change this to be the name of your book item.

world.afterEvents.itemUse.subscribe(event => {
  if (event.itemStack.typeId != "bps_cg:cg_book") return;

  const player = event.source;

showMainMenuForm(player)
 
})

giveASingleBook({
	itemTypeId: BOOK_ID
});

const overworld = world.getDimension("overworld");