package tv.tivilux.nativeplayer.ui.screens import androidx.compose.foundation.background import androidx.compose.foundation.border import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.BoxWithConstraints import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row 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.foundation.layout.width import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.text.KeyboardActions import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.foundation.verticalScroll import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.OutlinedTextFieldDefaults 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.graphics.Brush import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.painterResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.text.input.PasswordVisualTransformation import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import tv.tivilux.nativeplayer.BuildConfig import tv.tivilux.nativeplayer.R import tv.tivilux.nativeplayer.data.SupportReportContext import tv.tivilux.nativeplayer.ui.components.LuxButton import tv.tivilux.nativeplayer.ui.components.SupportIssue import tv.tivilux.nativeplayer.ui.components.SupportReportDialog import tv.tivilux.nativeplayer.ui.theme.LuxBg import tv.tivilux.nativeplayer.ui.theme.LuxGold import tv.tivilux.nativeplayer.ui.theme.LuxLine import tv.tivilux.nativeplayer.ui.theme.LuxMuted import tv.tivilux.nativeplayer.ui.theme.LuxPanel import tv.tivilux.nativeplayer.ui.theme.LuxText @Composable fun LoginScreen( error: String?, loading: Boolean, onLogin: (String, String, String) -> Unit, ) { var username by remember { mutableStateOf("") } var password by remember { mutableStateOf("") } var showSupportReport by remember { mutableStateOf(false) } BoxWithConstraints( Modifier.fillMaxSize().background( Brush.radialGradient(listOf(Color(0xFF283038), LuxBg), radius = 1200f) ) ) { // Most 1080p Android TV devices expose roughly 960x540dp at TV density. // The original desktop-sized spacing pushed the login button below that viewport. val compactHeight = maxHeight < 650.dp val compactWidth = maxWidth < 900.dp val outerHorizontal = if (compactWidth) 28.dp else 56.dp val outerVertical = if (compactHeight) 18.dp else 40.dp val columnGap = if (compactWidth) 28.dp else 60.dp val panelWidth = if (compactWidth) 390.dp else 430.dp val panelPadding = if (compactHeight) 22.dp else 30.dp val panelSpacing = if (compactHeight) 9.dp else 14.dp Row( Modifier.fillMaxSize().padding(horizontal = outerHorizontal, vertical = outerVertical), horizontalArrangement = Arrangement.spacedBy(columnGap), verticalAlignment = Alignment.CenterVertically, ) { if (!compactWidth) { Column(Modifier.weight(1.2f), verticalArrangement = Arrangement.Center) { androidx.compose.foundation.Image( painter = painterResource(R.drawable.tivilux_wordmark), contentDescription = "TiviLux", modifier = Modifier.width(if (compactHeight) 205.dp else 250.dp), ) Spacer(Modifier.height(if (compactHeight) 20.dp else 34.dp)) Text( "LIVING TV,\nREBUILT.", color = LuxText, fontSize = if (compactHeight) 46.sp else 60.sp, fontWeight = FontWeight.Light, lineHeight = if (compactHeight) 46.sp else 58.sp, ) Spacer(Modifier.height(if (compactHeight) 12.dp else 20.dp)) Text( "The TiviLux television experience — rebuilt as a native Android TV app for remote-first playback.", color = LuxMuted, fontSize = if (compactHeight) 15.sp else 18.sp, lineHeight = if (compactHeight) 21.sp else 27.sp, modifier = Modifier.fillMaxWidth(.86f), ) Spacer(Modifier.height(if (compactHeight) 16.dp else 28.dp)) Text("LIVE TV • GUIDE • MOVIES • SERIES", color = LuxGold, fontSize = 11.sp, letterSpacing = 1.7.sp) } } Column( Modifier .width(panelWidth) .background(LuxPanel.copy(alpha = .96f), RoundedCornerShape(24.dp)) .border(1.dp, LuxLine, RoundedCornerShape(24.dp)) .padding(panelPadding) .verticalScroll(rememberScrollState()), verticalArrangement = Arrangement.spacedBy(panelSpacing), ) { Text("CONNECT YOUR TV", color = LuxGold, fontSize = 10.sp, fontWeight = FontWeight.Bold, letterSpacing = 2.sp) Text("Welcome to TiviLux", color = LuxText, fontSize = if (compactHeight) 24.sp else 28.sp, fontWeight = FontWeight.SemiBold) Text( "Enter your TiviLux username and password.", color = LuxMuted, fontSize = if (compactHeight) 12.sp else 14.sp, ) LuxTextField("Username", username, { username = it }) OutlinedTextField( value = password, onValueChange = { password = it }, label = { Text("Password") }, visualTransformation = PasswordVisualTransformation(), singleLine = true, keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Password, imeAction = ImeAction.Done), keyboardActions = KeyboardActions(onDone = { if (!loading) onLogin(BuildConfig.DEFAULT_SERVER_URL, username, password) }), colors = fieldColors(), modifier = Modifier.fillMaxWidth(), ) if (!error.isNullOrBlank()) { Text(error, color = Color(0xFFFFAAAA), fontSize = 12.sp) } // Keep the primary action immediately below the password field so it remains // visible on 720p/1080p TV layouts with high Android TV display density. LuxButton( text = if (loading) "CONNECTING…" else "OPEN TIVILUX", onClick = { onLogin(BuildConfig.DEFAULT_SERVER_URL, username, password) }, modifier = Modifier.fillMaxWidth(), primary = true, enabled = !loading, ) LuxButton( text = "FORGOT LOGIN / REPORT A PROBLEM", onClick = { showSupportReport = true }, modifier = Modifier.fillMaxWidth(), enabled = !loading, ) if (!compactHeight) { Text( "Credentials stay on this device. HTTPS portals are recommended.", color = LuxMuted.copy(alpha = .8f), fontSize = 11.sp, ) } } } if (showSupportReport) { SupportReportDialog( details = SupportReportContext(accountHint = username.trim()), initialIssue = SupportIssue.LOGIN, loginHelpMode = true, onDismiss = { showSupportReport = false }, ) } } } @Composable private fun LuxTextField( label: String, value: String, onValueChange: (String) -> Unit, keyboardType: KeyboardType = KeyboardType.Text, ) { OutlinedTextField( value = value, onValueChange = onValueChange, label = { Text(label) }, keyboardOptions = KeyboardOptions(keyboardType = keyboardType, imeAction = ImeAction.Next), singleLine = true, colors = fieldColors(), modifier = Modifier.fillMaxWidth(), ) } @Composable private fun fieldColors() = OutlinedTextFieldDefaults.colors( focusedTextColor = LuxText, unfocusedTextColor = LuxText, focusedBorderColor = LuxGold, unfocusedBorderColor = LuxLine, focusedLabelColor = LuxGold, unfocusedLabelColor = LuxMuted, cursorColor = LuxGold, )