package com.syaroful.agrilinkvocpro.core.components

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.LinearProgressIndicator
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.syaroful.agrilinkvocpro.presentation.theme.MainGreen

@Composable
fun DownloadProgressDialog(
    showDialog: Boolean,
    message: String,
    progress: Float,
    onDismiss: () -> Unit
) {
    if (!showDialog) return

    AlertDialog(
        onDismissRequest = onDismiss,
        title = { Text(text = "Module Download", style = MaterialTheme.typography.titleMedium) },
        text = {
            Column(
                modifier = Modifier.fillMaxWidth(),
                horizontalAlignment = Alignment.CenterHorizontally
            ) {
                Text(text = message)
                Spacer(modifier = Modifier.height(16.dp))
                LinearProgressIndicator(
                    progress = {progress},
                    color = MainGreen,
                    trackColor = MainGreen.copy(alpha = 0.1f),
                )
            }
        },
        confirmButton = {
            TextButton(onClick = onDismiss) {
                Text(text = "Close", color = MainGreen)
            }
        }
    )
}

@Preview
@Composable
fun DownloadProgressDialogPreview() {
    DownloadProgressDialog(
        showDialog = true,
        message = "Downloading module...",
        progress = 0.5f,
        onDismiss = {}
    )
}