export const getRadarPosition = (mapData, entityCoords) => {
  // Check for undefined coordinates (0 is a valid coordinate)
  if (entityCoords.x === undefined || entityCoords.y === undefined) {
    return { x: 0, y: 0 };
  }

  // Check for undefined mapData properties (0 is a valid value)
  if (mapData.x === undefined || mapData.y === undefined || mapData.scale === undefined) {
    return { x: 0, y: 0 };
  }

  // Check for NaN or invalid values
  if (isNaN(mapData.x) || isNaN(mapData.y) || isNaN(mapData.scale) || 
      isNaN(entityCoords.x) || isNaN(entityCoords.y)) {
    return { x: 0, y: 0 };
  }

  const position = {
    x: (entityCoords.x - mapData.x) / mapData.scale / 1024,
    y: (((entityCoords.y - mapData.y) / mapData.scale) * -1.0) / 1024,
  };

  return position;
};

/**
 * Map-local pixel position from normalized 0–1 coords (unaffected by zoom/pan).
 * Converts normalized radar position (0-1) to actual pixel coordinates within the map image.
 * @param {number} mapW - Map width in pixels
 * @param {number} mapH - Map height in pixels  
 * @param {object} normPos - Normalized position {x: 0-1, y: 0-1}
 * @param {number} entityW - Entity width in pixels (for centering)
 * @param {number} entityH - Entity height in pixels (for centering)
 * @returns {{x: number, y: number}} Pixel coordinates
 */
export const getEntityTranslate = (mapW, mapH, normPos, entityW = 0, entityH = 0) => ({
  x: mapW * normPos.x - entityW * 0.5,
  y: mapH * normPos.y - entityH * 0.5,
});

export const playerColors = [
  // blue
  "#84c8ed",

  // green
  "#009a7d",

  // yellow
  "#eadd40",

  // orange
  "#df7d29",

  // purple
  "#b72b92",

  // white
  "#ffffff",
];

export const teamEnum = {
  none: 0,
  spectator: 1,
  terrorist: 2,
  counterTerrorist: 3,
};
