package com.pixelized.desktop.lwa.ui.composable.image

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.graphics.DefaultAlpha
import androidx.compose.ui.graphics.FilterQuality
import androidx.compose.ui.layout.ContentScale
import coil3.compose.AsyncImagePainter.Companion.DefaultTransform
import coil3.compose.AsyncImagePainter.State
import com.pixelized.desktop.lwa.utils.rememberBackgroundGradient
import com.pixelized.desktop.lwa.utils.rememberSaturationFilter

@Composable
fun DesaturatedAsyncImage(
    model: Any?,
    contentDescription: String?,
    modifier: Modifier = Modifier,
    transform: (State) -> State = DefaultTransform,
    onState: ((State) -> Unit)? = null,
    alignment: Alignment = Alignment.Center,
    contentScale: ContentScale = ContentScale.Fit,
    alpha: Float = DefaultAlpha,
    overlay: Brush? = rememberBackgroundGradient(),
    colorFilter: ColorFilter? = rememberSaturationFilter(saturation = 0f),
    filterQuality: FilterQuality = FilterQuality.Low,
    clipToBounds: Boolean = true,
) {
    Box(
        modifier = modifier,
    ) {
        LwaAsyncImage(
            model = model,
            contentDescription = contentDescription,
            modifier = Modifier.matchParentSize(),
            transform = transform,
            onState = onState,
            alignment = alignment,
            contentScale = contentScale,
            alpha = alpha,
            colorFilter = colorFilter,
            filterQuality = filterQuality,
            clipToBounds = clipToBounds,
        )
        if (overlay != null) {
            Box(
                modifier = Modifier
                    .matchParentSize()
                    .background(brush = overlay)
            )
        }
    }
}
