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.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
import eu.gaudian.translator.R
import eu.gaudian.translator.utils.Log
import eu.gaudian.translator.utils.findActivity
import eu.gaudian.translator.view.composable.AppAlertDialog
import eu.gaudian.translator.viewmodel.VocabularyViewModel

@Composable
fun DeleteItemsDialog(
    onDismiss: () -> Unit,
    categoryId: Int,
) {

    val activity = LocalContext.current.findActivity()
    val vocabularyViewModel: VocabularyViewModel = hiltViewModel(viewModelStoreOwner = activity)
    val categoryVocabularyItemDelete = vocabularyViewModel.categoryVocabularyItemDelete
    @Suppress("HardCodedStringLiteral")
    Log.d("DeleteItemsDialog", "categoryVocabularyItemDelete: $categoryVocabularyItemDelete")

    AppAlertDialog(
        onDismissRequest = onDismiss,
        title = {
            Text(text = stringResource(R.string.label_delete_items))
        },
        text = {
            Text(text = stringResource(R.string.text_are_you_sure_you_want_to_delete_all_items_in_this_category))
        },
        confirmButton = {
            TextButton(
                onClick = {
                    vocabularyViewModel.deleteVocabularyItemsByCategory(categoryId)
                    onDismiss()
                }
            ) {
                Text(stringResource(R.string.label_confirm))
            }
        },
        dismissButton = {
            TextButton(
                onClick = onDismiss
            ) {
                Text(stringResource(R.string.label_cancel))
            }
        }
    )
}