package com.syaroful.agrilinkvocpro.core.components

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.height
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.syaroful.agrilinkvocpro.R

@Composable
fun DownloadModuleConfirmationDialog(
    moduleName: String?,
    onDismiss: () -> Unit,
    onClickConfirm: () -> Unit
) {
    if (moduleName == null) return

    val message = when (moduleName) {
        "control_feature" -> "Apakah Anda ingin mendownload fitur Kontrol Aktuator?"
        "recipe_feature" -> "Apakah Anda ingin mendownload fitur Resep Pertumbuhan?"
        "price_prediction_feature" -> "Apakah Anda ingin mendownload fitur Prediksi Harga Komoditas?"
        "plant_disease_detection_feature" -> "Apakah Anda ingin mendownload fitur Deteksi Penyakit Tanaman?"
        else -> "Apakah Anda ingin mendownload modul ini?"
    }

    AlertDialog(
        icon = {
            Image(
                painter = painterResource(R.drawable.play_store),
                contentDescription = stringResource(id = R.string.play_store_icon_desc),
                modifier = Modifier.height(70.dp),
            )
        },

        title = {
            Text(
                stringResource(id = R.string.download_module_title),
                style = textTheme.bodyLarge,
            )
        },
        text = { Text(message) },
        onDismissRequest = onDismiss,
        confirmButton = {
            TextButton(
                onClick = {
                    onClickConfirm()
                    onDismiss()
                }
            ) {
                Text(stringResource(id = R.string.download))
            }
        },
        dismissButton = {
            TextButton(onClick = onDismiss) {
                Text(stringResource(id = R.string.cancel))
            }
        }
    )
}

@Preview(showBackground = true)
@Composable
fun PreviewDownloadModuleConfirmationDialog() {

    DownloadModuleConfirmationDialog(
        moduleName = "price_prediction_feature",
        onClickConfirm = {},
        onDismiss = {}
    )
}