package eu.gaudian.translator.view.dialogs

import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import eu.gaudian.translator.R
import eu.gaudian.translator.view.composable.AppAlertDialog
import eu.gaudian.translator.viewmodel.CategoryViewModel

@Composable
fun DeleteMultipleCategoriesDialog(
    categoryIds: List<Int>,
    categoryViewModel: CategoryViewModel,
    onDismiss: () -> Unit,
    onConfirm: () -> Unit,
) {
    AppAlertDialog(
        onDismissRequest = onDismiss,
        title = {
            Text(text = stringResource(R.string.text_delete_category))
        },
        text = {
            if (categoryIds.size == 1) {
                Text(text = stringResource(R.string.text_are_you_sure_you_want_to_delete_this_category))
            } else {
                Text(text = stringResource(R.string.text_are_you_sure_you_want_to_delete_these_categories, categoryIds.size))
            }
        },
        confirmButton = {
            TextButton(
                onClick = {
                    categoryIds.forEach { categoryId ->
                        categoryViewModel.deleteCategoryById(categoryId)
                    }
                    onConfirm()
                    onDismiss()
                }
            ) {
                Text(text = stringResource(R.string.label_confirm))
            }
        },
        dismissButton = {
            TextButton(
                onClick = onDismiss,
            ) {
                Text(text = stringResource(R.string.label_cancel))
            }
        }
    )
}