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 separate top and side particles
  const particleMap = {
    red: { top: 'pb_dino:block_marker_top_red', side: 'pb_dino:block_marker_side_red' },
    green: { top: 'pb_dino:block_marker_top_green', side: 'pb_dino:block_marker_side_green' },
    white: { top: 'pb_dino:block_marker_top_white', side: 'pb_dino:block_marker_side_white' }
  };

  // Use the provided color or default to red if not found
  const particleType = particleMap[color] || particleMap.red;
  const topParticle = particleType.top;
  const sideParticle = particleType.side;

  let mvm = new MolangVariableMap();

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

  // Side particles
  mvm.setFloat(`variable.dirx`, 1);
  mvm.setFloat(`variable.diry`, 0);
  mvm.setFloat(`variable.dirz`, 0);
  world.getDimension(dimension).spawnParticle(sideParticle, { x: location.x + 0.86, y: location.y + 0.6, z: location.z + 0.5 }, mvm);
  world.getDimension(dimension).spawnParticle(sideParticle, { x: location.x + 0.16, y: location.y + 0.6, 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(sideParticle, { x: location.x + 0.5, y: location.y + 0.6, z: location.z + 0.86 }, mvm);
  world.getDimension(dimension).spawnParticle(sideParticle, { x: location.x + 0.5, y: location.y + 0.6, z: location.z + 0.16 }, mvm);
}
