package main

import androidx.compose.foundation.layout.*
import androidx.compose.material.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import main.component.buttonComponent
import main.component.dropdownButtonComponent

@Composable
fun choixLangagePage(
    languageManager: LanguageManager,
    onBackClick: () -> Unit,
    onKotlinClick: () -> Unit,
    onPythonClick: () -> Unit,
    onJavaClick: () -> Unit,
    onJavaScriptClick: () -> Unit,
    onProjectClick: () -> Unit,
    onCodeToVerifyClick: () -> Unit
) {
    var isCompareClicked by remember { mutableStateOf(false) }
    val noFileSnackbarVisibleState = remember { mutableStateOf(false) }

    Column(
        modifier = Modifier.fillMaxSize(),
        verticalArrangement = Arrangement.Top, // Align content at the top
        horizontalAlignment = Alignment.CenterHorizontally
    ) {
        Text(text = languageManager.getLanguageChoiceTitle(), style = MaterialTheme.typography.h3)
    }

    Column(
        modifier = Modifier
            .fillMaxSize()  // Fills the maximum available width
            .padding(50.dp),
        // Align the content in the center vertically and horizontally
        verticalArrangement = Arrangement.Center,
        horizontalAlignment = Alignment.CenterHorizontally

    ) {
        Button(
            onClick = onKotlinClick,
            modifier = Modifier
                .width(150.dp),
            colors = ButtonDefaults.buttonColors(
                backgroundColor = customRedColor,
                contentColor = Color.White
            ),
            enabled = true
        ) {
            Text("Kotlin")
        }

        Button(
            onClick = onPythonClick,
            modifier = Modifier
                .width(150.dp),
            colors = ButtonDefaults.buttonColors(
                backgroundColor = customRedColor,
                contentColor = Color.White
            ),
            enabled = false
        ) {
            Text("Python")
        }

        Button(
            onClick = onJavaClick,
            modifier = Modifier
                .width(150.dp),
            colors = ButtonDefaults.buttonColors(
                backgroundColor = customRedColor,
                contentColor = Color.White
            ),
            enabled = false
        ) {
            Text("Java")
        }

        Button(
            onClick = onJavaScriptClick,
            modifier = Modifier
                .width(150.dp),
            colors = ButtonDefaults.buttonColors(
                backgroundColor = customRedColor,
                contentColor = Color.White
            )
        ) {
            Text("JavaScript")
        }

        // Faire un bouton qui affiche la vue "occurence" si on a déjà importer un fichier
        // Sinon afficher un snackbar qui dit qu'il faut importer un fichier
        Button(
            onClick = {
                if (mostUsedWordList.isEmpty()) {
                    noFileSnackbarVisibleState.value = true
                    return@Button
                } else {
                    isCompareClicked = true
                    currentPage.value = "occurrence"
                }
            },
            modifier = Modifier
                .width(150.dp),
            colors = ButtonDefaults.buttonColors(
                backgroundColor = customRedColor,
                contentColor = Color.White
            ),
            enabled = mostUsedWordList.isNotEmpty()
        ) {
            Text("Mots parsés")
        }
    }

    Column(
        modifier = Modifier.fillMaxSize().padding(20.dp),
        verticalArrangement = Arrangement.Bottom,
        horizontalAlignment = Alignment.CenterHorizontally
    ) {
        buttonComponent(
            text = languageManager.getBackText(),
            onClick = onBackClick,
            icon = Icons.Filled.ArrowBack
        )
    }
    dropdownButtonComponent(
        languageManager = languageManager,
        items = listOf(languageManager.getGlossaryText(), languageManager.getCodeToVerifyText(), languageManager.getCompareText())
    ) { selectedOption ->
        // Handle the selected option
        when (selectedOption) {
            languageManager.getGlossaryText() -> onProjectClick()
            languageManager.getCodeToVerifyText() -> onCodeToVerifyClick()
            languageManager.getCompareText() -> {
                if (mostUsedWordList.isEmpty()) {
                    noFileSnackbarVisibleState.value = true
                    return@dropdownButtonComponent
                } else {
                    currentPage.value = "compareProject"
                }
            }
        }
    }
}