package com.za.ext

import androidx.compose.foundation.clickable
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableLongStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import com.za.base.Const

@Composable
fun Modifier.noDoubleClick(onClick: () -> Unit): Modifier {
    var lastClickTime by remember { mutableLongStateOf(value = 0L) }
    return clickable(enabled = true) {
        val currentTimeMillis = System.currentTimeMillis()
        if (currentTimeMillis - Const.DoubleClickTime >= lastClickTime) {
            onClick()
            lastClickTime = currentTimeMillis
        }
    }
}