package eu.gaudian.translator.view.dialogs

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.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import eu.gaudian.translator.R
import eu.gaudian.translator.ui.theme.ThemePreviews
import eu.gaudian.translator.view.composable.AppAlertDialog
import eu.gaudian.translator.view.composable.DialogButton

@Composable
fun WhatsNewDialog(
    onDismissRequest: () -> Unit,
    onContinue: () -> Unit,
    changelogContent: String
) {
    AppAlertDialog(
        onDismissRequest = onDismissRequest,
        confirmButton = {
            Row(
                modifier = Modifier
                    .fillMaxWidth()
                    .padding(horizontal = 16.dp),
                horizontalArrangement = Arrangement.End
            ) {
                DialogButton(
                    onClick = onContinue,
                    text = stringResource(R.string.label_continue),
                    isPrimary = false
                )
            }
        },
        title = {
            Text(
                text = stringResource(R.string.whats_new_title),
                style = MaterialTheme.typography.headlineSmall,
                fontWeight = FontWeight.Bold
            )
        },
        text = {
            Column(modifier = Modifier.verticalScroll(rememberScrollState())) {
                Text(
                    text = stringResource(R.string.whats_new_changelog_title),
                    style = MaterialTheme.typography.titleMedium,
                    fontWeight = FontWeight.SemiBold,
                    modifier = Modifier.padding(bottom = 8.dp)
                )
                Text(
                    text = changelogContent,
                    style = MaterialTheme.typography.bodyMedium
                )
            }
        }
    )
}

@Suppress("HardCodedStringLiteral")
@ThemePreviews
@Composable
fun WhatsNewDialogPreview() {
    WhatsNewDialog(
        onDismissRequest = {},
        onContinue = {},
        changelogContent = """
            • New feature: Dark mode support for a better viewing experience in low-light environments.
            • New feature: Offline translation capabilities. Download language packs to translate without an internet connection.
            • New feature: Voice input. Speak directly into your device for instant translation.
            • New feature: Conversation mode. A split-screen interface to facilitate bilingual conversations.
            • Improvement: Enhanced translation accuracy for several language pairs.
            • Improvement: UI has been redesigned for a more intuitive and modern look.
            • Improvement: Performance has been optimized, resulting in faster translation times.
            • Improvement: Reduced application size.
            • Bug fix: Fixed an issue where the app would crash on certain older devices.
            • Bug fix: Corrected a bug that caused incorrect translations for specific phrases.
            • Bug fix: Addressed a memory leak that could slow down the device over time.
            • New language: Added support for Klingon.
            • New language: Added support for Elvish.
            • Removed: Phased out support for Internet Explorer 6.
            • Just kidding about those last three. Or are we?
            • Lots and lots of other minor bug fixes and performance improvements to make your experience smoother. We've been busy!
        """.trimIndent()
    )
}