package com.laseroptek.raman.utils.slider

import android.graphics.Paint
import android.graphics.Typeface
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

data class SliderConfiguration(
    val barHeight: Dp = 12.dp,
    val barColor: Color = Color.LightGray,
    val barColorInRange: Color = Color.Black,
    val barCornerRadius: Dp = 6.dp,
    val touchCircleRadius: Dp = 16.dp,
    val touchCircleShadowSize: Dp = 4.dp,
    val touchCircleShadowTouchedSizeAddition: Dp = 2.dp,
    val touchCircleColor: Color = Color.White,
    val textColorInRange: Color = Color.Black,
    val textColorOutOfRange: Color = Color.LightGray,
    val textSize: TextUnit = 16.sp,
    val textOffset: Dp = 8.dp,
    val stepMarkerColor: Color = Color.DarkGray,
) {
    internal fun barHeightPx(density: Density): Float = with(density) { barHeight.toPx() }
    internal fun barCornerRadiusPx(density: Density): Float = with(density) { barCornerRadius.toPx() }
    internal fun touchCircleRadiusPx(density: Density): Float = with(density) { touchCircleRadius.toPx() }
    internal fun touchCircleShadowSizePx(density: Density): Float = with(density) { touchCircleShadowSize.toPx() }
    internal fun touchCircleShadowTouchedSizeAdditionPx(density: Density): Float = with(density) { touchCircleShadowTouchedSizeAddition.toPx() }
    internal fun stepMarkerRadiusPx(density: Density): Float = with(density) { (barHeight / 4).toPx() }
    internal fun textSizePx(density: Density): Float = with(density) { textSize.toPx() }

    internal fun textInRangePaint(density: Density): Paint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
        color = textColorInRange.toArgb()
        this.textSize = textSizePx(density)
    }

    internal fun textSelectedPaint(density: Density): Paint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
        color = textColorInRange.toArgb()
        this.textSize = textSizePx(density)
        this.typeface = Typeface.DEFAULT_BOLD
    }

    internal fun textOutOfRangePaint(density: Density): Paint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
        color = textColorOutOfRange.toArgb()
        this.textSize = textSizePx(density)
    }
}