package com.aiosman.ravenow.ui.modifiers

import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.composed
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

inline fun Modifier.noRippleClickable(crossinline onClick: () -> Unit): Modifier = composed {
    this.clickable(indication = null,
        interactionSource = remember { MutableInteractionSource() }) {
        onClick()
    }
}


inline fun Modifier.noRippleClickable(
    debounceTime: Long = 300L,
    crossinline onClick: () -> Unit
): Modifier = composed {
    var job: Job? = null
    val scope = rememberCoroutineScope()
    this.clickable(
        indication = null,
        interactionSource = remember { MutableInteractionSource() }
    ) {
        job?.cancel()
        job = scope.launch {
            delay(debounceTime)
            onClick()
        }
    }
}


