package de.softwareapp_hb.privateqrscanner.ui.screens

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.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Button
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import de.softwareapp_hb.privateqrscanner.R

@Composable
fun HomeScreen(
    historyEnabled: Boolean,
    onHistoryToggle: (Boolean) -> Unit,
    onScanClick: () -> Unit
) {
    val showPrivacyDialog = remember { mutableStateOf(false) }

    if (showPrivacyDialog.value) {
        PrivacyPolicyDialog(onDismiss = { showPrivacyDialog.value = false })
    }

    Column(
        modifier = Modifier
            .fillMaxSize()
            .padding(24.dp),
        verticalArrangement = Arrangement.Center
    ) {
        Button(
            onClick = onScanClick,
            modifier = Modifier.fillMaxWidth()
        ) {
            Text(text = stringResource(R.string.scan))
        }

        Spacer(modifier = Modifier.height(24.dp))

        Column(modifier = Modifier.fillMaxWidth()) {
            Text(text = stringResource(R.string.save_history), style = MaterialTheme.typography.titleMedium)
            Spacer(modifier = Modifier.height(8.dp))
            Switch(checked = historyEnabled, onCheckedChange = onHistoryToggle)
        }

        Spacer(modifier = Modifier.height(24.dp))

        TextButton(onClick = { showPrivacyDialog.value = true }) {
            Text(
                text = stringResource(R.string.privacy),
                style = MaterialTheme.typography.titleMedium,
                textAlign = TextAlign.Start
            )
        }
    }
}
