package com.fastest.pass.app

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableFloatStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.unit.dp
import com.fastest.pass.R
import kotlinx.coroutines.delay

@Composable
fun GenericLoader(loader: Boolean) {
    if (loader) {

        var progress by remember { mutableFloatStateOf(0.1F) }

        LaunchedEffect(key1 = Unit) {
            while (true) {
                for (i in 1..100) {
                    progress = i.toFloat() / 100F
                    delay(50)
                }
                progress = 0.1F
            }
        }

        Box(modifier = Modifier.fillMaxSize(),
            contentAlignment = Alignment.Center){
            CircularProgressIndicator(
                progress = { progress },
                modifier = Modifier
                    .size(50.dp)
                    .align(Alignment.Center),
                color = colorResource(id = R.color.yellow_text),
                strokeWidth = 5.dp,
            )
        }


    }
}