import * as mc from '@minecraft/server';
import * as mcui from '@minecraft/server-ui';
import * as racoAPI from '../raco-API';
import { colorSelected } from './wirelessFunctions';


export function leverInteract(player, block){
    const item = player.getComponent('equippable')?.getEquipment("Mainhand")
    if (item?.typeId == 'vtng_rt:pliers'){
        const selectedColor = colorSelected(player, block, setModule)
    } else if (block.permutation.getState('vtng_rt:on') == false) {
        block.dimension.playSound('random.click', block.center(), {pitch: 0.6, volume: 1})
        racoAPI.setPermutation(block, 'vtng_rt:on', true)
        block.dimension.spawnParticle('vtng_rt:redstone_out', {x:block.center().x, y:block.y, z:block.center().z})
        mc.world.setDynamicProperty(`${block.dimension.id},${JSON.stringify(block.location)}`, `vtng_rt:${block.permutation.getState('vtng_rt:color')}`)
    } else {
        block.dimension.playSound('random.click', block.center(), {pitch: 0.6, volume: 1})
        racoAPI.setPermutation(block, 'vtng_rt:on', false),
        mc.world.setDynamicProperty(`${block.dimension.id},${JSON.stringify(block.location)}`, undefined)
    }
}
function setModule(block, color){
    racoAPI.setPermutation(block, 'vtng_rt:color', color)
} 
