@file:Suppress("AssignedValueIsNeverRead")

package eu.gaudian.translator.view.dialogs

import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
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.findActivity
import eu.gaudian.translator.view.composable.AppFabMenu
import eu.gaudian.translator.view.composable.AppIcons
import eu.gaudian.translator.view.composable.FabMenuItem
import eu.gaudian.translator.viewmodel.LanguageViewModel
import eu.gaudian.translator.viewmodel.VocabularyViewModel

@Composable
fun VocabularyMenu(
    modifier: Modifier = Modifier,
    showFabText : Boolean = true
) {
    val activity = LocalContext.current.findActivity()
    val languageViewModel: LanguageViewModel = hiltViewModel(viewModelStoreOwner = activity)
    val vocabularyViewModel: VocabularyViewModel = hiltViewModel(viewModelStoreOwner = activity)
    var showAddVocabularyDialog by remember { mutableStateOf(false) }
    var showImportVocabularyDialog by remember { mutableStateOf(false) }
    var showAddCategoryDialog by remember { mutableStateOf(false) }

    val menuItems = listOf(
        FabMenuItem(
            text = stringResource(R.string.label_add_vocabulary),
            imageVector = AppIcons.Add,
            onClick = { showAddVocabularyDialog = true }
        ),
        FabMenuItem(
            text = stringResource(R.string.menu_import_vocabulary),
            imageVector = AppIcons.AI,
            onClick = { showImportVocabularyDialog = true }
        ),
        FabMenuItem(
            text = stringResource(R.string.label_add_category),
            imageVector = AppIcons.Add,
            onClick = { showAddCategoryDialog = true }
        )
    )

    AppFabMenu(items = menuItems, modifier = modifier, title = stringResource(R.string.label_add_vocabulary), showFabText = showFabText)

    if (showAddVocabularyDialog) {
        AddVocabularyDialog(
            onDismissRequest = { showAddVocabularyDialog = false }
        )
    }

    if (showImportVocabularyDialog) {
        ImportVocabularyDialog(
            languageViewModel = languageViewModel,
            vocabularyViewModel = vocabularyViewModel,
            onDismiss = { showImportVocabularyDialog = false }
        )
    }

    if (showAddCategoryDialog) {
        AddCategoryDialog(
            onDismiss = { showAddCategoryDialog = false }
        )
    }
}