import { world, MolangVariableMap } from "@minecraft/server";

export default function highlightBlock(block, color) {
  let location = block.location;
  let dimension = block.dimension.id;

  // Map color names to particle names
  const particleMap = {
    red: 'pb_plane:block_marker_red',
    green: 'pb_plane:block_marker_green',
    white: 'pb_plane:block_marker_white',
    yellow: 'pb_plane:block_marker_yellow',
    // Add more colors here if needed
  };

  // Use the provided color or default to red if not found
  const particleName = particleMap[color] || particleMap.red;

  let mvm = new MolangVariableMap();
  
  mvm.setFloat(`variable.dirx`, 0);
  mvm.setFloat(`variable.diry`, 1);
  mvm.setFloat(`variable.dirz`, 0);
  world.getDimension(dimension).spawnParticle(particleName, { x: location.x + 0.5, y: location.y - 0.01, z: location.z + 0.5 }, mvm);
  world.getDimension(dimension).spawnParticle(particleName, { x: location.x + 0.5, y: location.y + 1.01, z: location.z + 0.5 }, mvm);

  mvm.setFloat(`variable.dirx`, 1);
  mvm.setFloat(`variable.diry`, 0);
  mvm.setFloat(`variable.dirz`, 0);
  world.getDimension(dimension).spawnParticle(particleName, { x: location.x + 1.01, y: location.y + 0.5, z: location.z + 0.5 }, mvm);
  world.getDimension(dimension).spawnParticle(particleName, { x: location.x - 0.01, y: location.y + 0.5, z: location.z + 0.5 }, mvm);

  mvm.setFloat(`variable.dirx`, 0);
  mvm.setFloat(`variable.diry`, 0);
  mvm.setFloat(`variable.dirz`, 1);
  world.getDimension(dimension).spawnParticle(particleName, { x: location.x + 0.5, y: location.y + 0.5, z: location.z + 1.01 }, mvm);
  world.getDimension(dimension).spawnParticle(particleName, { x: location.x + 0.5, y: location.y + 0.5, z: location.z - 0.01 }, mvm);
}
