package club.clubk.ktag.apps.core.ui

import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import kotlin.math.max
import kotlin.math.min

/**
 * Utility functions for color manipulation.
 */
object ColorUtils {

    /**
     * Washes out a color by reducing its saturation and optionally increasing brightness.
     */
    fun washOutColor(color: Color, saturationFactor: Float, brightnessFactor: Float = 1.0f): Color {
        val hsv = FloatArray(3)
        android.graphics.Color.colorToHSV(color.toArgb(), hsv)

        // Reduce saturation
        hsv[1] = max(0f, min(1f, hsv[1] * saturationFactor))

        // Adjust brightness (Value)
        hsv[2] = max(0f, min(1f, hsv[2] * brightnessFactor))

        return Color(android.graphics.Color.HSVToColor(hsv))
    }

    /**
     * Creates a pastel version of the color.
     */
    fun makePastel(color: Color): Color {
        return washOutColor(color, 0.3f, 1.2f)
    }

    /**
     * Converts an Android color int to Compose Color.
     */
    fun fromAndroidColor(androidColor: Int): Color {
        return Color(androidColor)
    }
}
