// Copyright (C) 2026 Jason M. Schwefel. All Rights Reserved.
package com.coldboreballisticsllc.scopedope.label.renderer

import android.graphics.*
import kotlin.math.abs

// ── Shared sticker color palette ──────────────────────────────────────────────
// Values match pdf_generator.py reference palette.

internal val STICKER_BLUE  = Color.parseColor("#1565C0")
internal val STICKER_RED   = Color.parseColor("#C62828")
internal val STICKER_GREEN = Color.parseColor("#2E7D32")
internal val STICKER_AMBER = Color.parseColor("#E65100")
internal val STICKER_GRAY  = Color.parseColor("#666666")

// ── Shared formatting helpers ─────────────────────────────────────────────────

internal fun fmtDist(yards: Int): String = yards.toString()

internal fun fmtAdj(mil: Double, decimals: Int, sym: ElevationSymbol = ElevationSymbol.PLUS_MINUS): String {
    if (mil == 0.0) return "0.${"0".repeat(decimals)}"
    return if (sym == ElevationSymbol.ARROWS) {
        val arrow = if (mil > 0) "↑" else "↓"
        "$arrow%.${decimals}f".format(abs(mil))
    } else {
        val sign = if (mil > 0) "+" else ""
        "$sign%.${decimals}f".format(mil)
    }
}

internal fun fmtWind(mil: Double, decimals: Int): String {
    if (abs(mil) < 0.05) return ""
    val arrow = if (mil > 0) ">" else "<"
    return "$arrow%.${decimals}f".format(abs(mil))
}

internal fun adjColor(mil: Double, semantic: Boolean): Int = when {
    !semantic -> Color.BLACK
    mil > 0   -> STICKER_GREEN
    mil < 0   -> STICKER_RED
    else      -> Color.BLACK
}

internal fun buildPaint(
    typeface: Typeface,
    textSize: Float,
    color:    Int         = Color.BLACK,
    align:    Paint.Align = Paint.Align.LEFT,
) = Paint(Paint.ANTI_ALIAS_FLAG).apply {
    this.typeface  = typeface
    this.textSize  = textSize
    this.color     = color
    this.textAlign = align
}
