import SwiftUI

/// Shown for `AppState.phase == .signedOut` (see `App/RootView.swift`, which
/// depends on this exact type name and its zero-argument initializer). Owns
/// simple in-feature navigation between "Anmelden", "Registrieren", and the
/// post-signup "bitte bestätige deine E-Mail" screen — none of that belongs
/// in `AppState` since none of it affects whether the user is actually
/// signed in; `AppState.phase` only changes once a real session exists.
struct AuthFlowView: View {
    private enum Screen: Equatable {
        case login
        case signup
        case verificationPending(email: String)
    }

    @State private var screen: Screen = .login

    var body: some View {
        Group {
            switch screen {
            case .login:
                LoginView(onSwitchToSignup: { screen = .signup })
            case .signup:
                SignupView(
                    onSignupSucceeded: { email in screen = .verificationPending(email: email) },
                    onSwitchToLogin: { screen = .login }
                )
            case .verificationPending(let email):
                VerificationPendingView(email: email, onGoToLogin: { screen = .login })
            }
        }
        .animation(.default, value: screen)
    }
}
