package dev.ulfrx.recipe.ui.screens.auth

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.safeContentPadding
import androidx.compose.foundation.text.BasicText
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import dev.lokksmith.compose.rememberAuthFlowLauncher
import dev.ulfrx.recipe.auth.ComposeAuthBrowser
import dev.ulfrx.recipe.shared.dto.User
import dev.ulfrx.recipe.ui.components.controls.RecipeOutlinedButton
import dev.ulfrx.recipe.ui.theme.RecipeTheme
import org.jetbrains.compose.resources.stringResource
import recipe.composeapp.generated.resources.Res
import recipe.composeapp.generated.resources.auth_sign_out_button
import recipe.composeapp.generated.resources.auth_welcome_format

/**
 * Phase 2 placeholder: welcome message + logout. Phase 3 replaces this with `HouseholdGate`.
 */
@Composable
fun PostLoginPlaceholderScreen(
    user: User,
    viewModel: PostLoginViewModel,
) {
    val launcher = rememberAuthFlowLauncher()
    val browser = remember(launcher) { ComposeAuthBrowser(launcher) }
    Box(
        modifier =
            Modifier
                .fillMaxSize()
                .background(RecipeTheme.colors.surface),
    ) {
        Column(
            modifier =
                Modifier
                    .fillMaxSize()
                    .safeContentPadding()
                    .padding(horizontal = 16.dp),
            horizontalAlignment = Alignment.CenterHorizontally,
            verticalArrangement = Arrangement.Center,
        ) {
            BasicText(
                text = stringResource(Res.string.auth_welcome_format, user.displayName),
                style =
                    RecipeTheme.typography.title.copy(
                        color = RecipeTheme.colors.content,
                        textAlign = TextAlign.Center,
                    ),
            )
            Spacer(Modifier.height(24.dp))
            RecipeOutlinedButton(
                text = stringResource(Res.string.auth_sign_out_button),
                onClick = { viewModel.onSignOutClick(browser) },
            )
        }
    }
}
