@file:Suppress("AssignedValueIsNeverRead")

package eu.gaudian.translator.view.vocabulary

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
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.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
import eu.gaudian.translator.R
import eu.gaudian.translator.utils.findActivity
import eu.gaudian.translator.view.LocalConnectionConfigured
import eu.gaudian.translator.view.composable.AppButton
import eu.gaudian.translator.view.dialogs.AddVocabularyDialog
import eu.gaudian.translator.view.dialogs.ImportVocabularyDialog
import eu.gaudian.translator.viewmodel.LanguageViewModel
import eu.gaudian.translator.viewmodel.VocabularyViewModel

@Composable
fun NoVocabularyScreen(){

    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) }

    val connectionConfigured = LocalConnectionConfigured.current


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

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

    Column(
        modifier = Modifier
            .fillMaxSize()
            .padding(16.dp),
        verticalArrangement = Arrangement.Center,
        horizontalAlignment = Alignment.CenterHorizontally
    ) {

    Image(
        modifier = Modifier.size(200.dp),
        painter = painterResource(id = R.drawable.ic_empty),
        contentDescription = stringResource(id = R.string.text_vocab_empty)
    )
    Spacer(modifier = Modifier.size(16.dp))
    Text(
        text = stringResource(id = R.string.text_vocab_empty),
        style = MaterialTheme.typography.titleMedium,
        color = MaterialTheme.colorScheme.onBackground,
        textAlign = TextAlign.Center
    )
        Spacer(modifier = Modifier.size(16.dp))

        AppButton(modifier = Modifier.fillMaxWidth(), onClick = { showAddVocabularyDialog = true }) {
            Text(stringResource(R.string.label_add_vocabulary))
        }
        if(connectionConfigured) {
            AppButton(modifier = Modifier.fillMaxWidth(), onClick = { showImportVocabularyDialog = true }) {
                Text(stringResource(R.string.label_create_vocabulary_with_ai))
            }
        }

    }
}