import * as mc from "@minecraft/server";
import { highlightBlock } from "../sgs_cake_lib";

export class preptableManager {

    static onplace(data) {
        const block = data.block;
        const below = block.below();

        if (below.hasTag("sgs_cake_preptable_base")) {
            block.setPermutation(block.permutation.withState('sgs_cake:can_craft', 1));

            if (block.hasTag("sgs_cake_preptable_chop")) below.setPermutation(below.permutation.withState('sgs_cake:crafting_station', 1)); //chop board
            if (block.hasTag("sgs_cake_preptable_slab")) below.setPermutation(below.permutation.withState('sgs_cake:crafting_station', 2)); //quartz slab

            highlightBlock(block);
            highlightBlock(below);
        }
    }

    static destroy(data) {
        const block = data.block;
        const below = block.below();
        if (below.hasTag("sgs_cake_preptable_base")) {
            below.setPermutation(below.permutation.withState('sgs_cake:crafting_station', 0));
        }
    }

    static onplaceBase(data) {
        const block = data.block;
        const above = block.above();

        if (above.hasTag("sgs_cake_preptable_top")) {
            above.setPermutation(above.permutation.withState('sgs_cake:can_craft', 1));

            if (above.hasTag("sgs_cake_preptable_chop")) block.setPermutation(block.permutation.withState('sgs_cake:crafting_station', 1)); //chop board
            if (above.hasTag("sgs_cake_preptable_slab")) block.setPermutation(block.permutation.withState('sgs_cake:crafting_station', 2)); //quartz slab

            highlightBlock(block);
            highlightBlock(above);
        }

        if (above.hasTag("sgs_farm_preptable_top")) {
            above.setPermutation(above.permutation.withState('sgs_farm:can_craft', 1));

            if (above.hasTag("sgs_farm_preptable_top")) block.setPermutation(block.permutation.withState('sgs_farm:crafting_station', 1)); //chop board

            highlightBlock(block);
            highlightBlock(above);
        }
    }

    static destroyBase(data) {
        const block = data.block;
        const above = block.above();
        if (above.hasTag("sgs_cake_preptable_top")) {
            above.setPermutation(above.permutation.withState('sgs_cake:can_craft', 0));
        }
        if (above.hasTag("sgs_farm_preptable_top")) {
            above.setPermutation(above.permutation.withState('sgs_farm:can_craft', 0));
        }
    }
}