package eu.gaudian.translator.view.dialogs

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.ListItem
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import eu.gaudian.translator.R
import eu.gaudian.translator.model.VocabularyStage
import eu.gaudian.translator.view.composable.AppDialog
import eu.gaudian.translator.view.composable.ComponentDefaults
import eu.gaudian.translator.view.composable.DialogButton

@Composable
fun StageSelectionDialog(
    onStageSelected: (VocabularyStage?) -> Unit,
    onDismissRequest: () -> Unit
) {

    AppDialog(onDismissRequest = onDismissRequest, title = {
        Text(text = stringResource(R.string.label_select_stage))
    }) {



            Column(
                modifier = Modifier
                    .fillMaxWidth()
                    .clip(ComponentDefaults.CardShape)
            ) {
                VocabularyStage.entries.forEach { stage ->
                    ListItem(
                        headlineContent = {
                            Text(text = stage.toString(LocalContext.current))
                        },
                        modifier = Modifier
                            .fillMaxWidth()
                            .clickable {
                                onStageSelected(stage)
                                onDismissRequest()
                            }
                            .padding(vertical = 0.dp)
                    )
                }
            }

            Row(
                modifier = Modifier
                    .fillMaxWidth()
                    .padding(top = 8.dp),
                horizontalArrangement = Arrangement.End
            ) {
                DialogButton(
                    onClick = onDismissRequest,
                ) {
                    Text(stringResource(R.string.label_cancel))
                }
            }
    }
}

@Preview
@Composable
fun StageSelectionDialogPreview() {
    StageSelectionDialog(onStageSelected = {}, onDismissRequest = {})
}