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 lampTick(block){
    let on = mc.world?.getDynamicPropertyIds()?.some(thisProperty =>
        mc?.world?.getDynamicProperty(thisProperty)?.replace('vtng_rt:', '') === block?.permutation?.getState('vtng_rt:color')
    )
    if (block.permutation.getState("vtng_rt:chain") == false && !block.above().isAir){
        racoAPI.setPermutation(block, 'vtng_rt:chain', true)
    } else if (block.permutation.getState("vtng_rt:chain") == true && block.above().isAir){
        racoAPI.setPermutation(block, 'vtng_rt:chain', false)
    }
    if (block.permutation.getState("vtng_rt:on") == false && on){
        block.dimension.spawnParticle('vtng_rt:redstone_inp', block.center())
    }
    racoAPI.setPermutation(block, 'vtng_rt:on', on)
}

export function lampInteract(player, block){
    const item = player.getComponent('equippable')?.getEquipment("Mainhand")
    if (item?.typeId == 'vtng_rt:pliers'){
        const selectedColor = colorSelected(player, block, setModule)
    }
}
function setModule(block, color){
    racoAPI.setPermutation(block, 'vtng_rt:color', color)
} 