package com.example.wabi.view.components.colors

import android.os.Build
import androidx.annotation.RequiresApi
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import android.graphics.Color as AndroidColor

@RequiresApi(Build.VERSION_CODES.O)
fun darkenColor(color: Color, factor: Float = 0.2f): Color {
    val androidColor = color.toArgb()
    val hsl = FloatArray(3)

    AndroidColor.colorToHSV(androidColor, hsl)
    hsl[2] -= factor
    hsl[2] = hsl[2].coerceIn(0f, 1f)
    return Color(AndroidColor.HSVToColor(hsl))
}