package mg.dot.feufaro.ui

import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.ScrollbarStyle
import androidx.compose.foundation.VerticalScrollbar
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.rememberScrollbarAdapter
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp

@Composable
actual fun MyVerticalScrollbar (
    modifier: Modifier,
    scrollState: ScrollState?,
    lazyListState: LazyListState?,
    content: @Composable () -> Unit,
) {
    Box ( modifier = Modifier.fillMaxSize()){
        content()

        val adapter = when {
            lazyListState != null -> rememberScrollbarAdapter(lazyListState)
            scrollState != null -> rememberScrollbarAdapter(scrollState)
            else -> null
        }

        val scrollbarUnhoverColor = MaterialTheme.colorScheme.secondary.copy(alpha = 0.85f)
        val scrollbarHoverColor = MaterialTheme.colorScheme.secondary
        val scrollbarBackground = MaterialTheme.colorScheme.onSecondary.copy(alpha = 0.25f)

        if (adapter != null) {
            VerticalScrollbar(
                adapter = adapter,
                modifier = modifier.fillMaxHeight(0.5f).background(scrollbarBackground),
                style = ScrollbarStyle(
                    minimalHeight = 16.dp,
                    thickness = 8.dp,
                    shape = RoundedCornerShape(4.dp),
                    hoverDurationMillis = 250,
                    unhoverColor = scrollbarUnhoverColor,
                    hoverColor = scrollbarHoverColor
                )
            )
            //content()
        }
    }
}
