export function useRadarCoordinateTransform(
  angle: number,
  coordinates: [number, number, number, number]
) {
  const [xStart, , , yEnd] = coordinates
  const adjustedAngle = angle - 90

  function editorToRadar(x: number, y: number): { x: number; y: number } {
    return { x, y }
  }

  function radarToEditor(x: number, y: number): { x: number; y: number } {
    return { x, y }
  }

  function radarToCss(x: number, y: number): { left: number; top: number } {
    let rx = x,
      ry = y
    switch (adjustedAngle) {
      case 90:
        ;[rx, ry] = [y, -x]
        break
      case 180:
        ;[rx, ry] = [-x, -y]
        break
      case 270:
        ;[rx, ry] = [-y, x]
        break
    }
    return {
      left: rx - xStart,
      top: yEnd - ry,
    }
  }

  function cssToRadar(left: number, top: number): { x: number; y: number } {
    const lx = left + xStart
    const ty = yEnd - top
    switch (adjustedAngle) {
      case 90:
        return { x: -ty, y: lx }
      case 180:
        return { x: -lx, y: -ty }
      case 270:
        return { x: ty, y: -lx }
      default:
        return { x: lx, y: ty }
    }
  }

  // ✅ 新增：编辑角度 → 雷达角度
  function editorAngleToRadar(editorAngle: number): number {
    return (editorAngle + angle) % 360
  }

  // ✅ 新增：雷达角度 → 编辑角度
  function radarAngleToEditor(radarAngle: number): number {
    return (radarAngle - angle + 360) % 360
  }

  return {
    editorToRadar,
    radarToEditor,
    radarToCss,
    cssToRadar,
    editorAngleToRadar,
    radarAngleToEditor,
  }
}
