//
//  AuthContainerView.swift
//  AppClientBaseSwift
//
//  Container view for authentication flows
//  View container cho các luồng xác thực
//

import SwiftUI
import Combine

// MARK: - Auth Container View
// View Container Auth

/// Container that manages navigation between auth screens
/// Container quản lý điều hướng giữa các màn hình auth
struct AuthContainerView: View {

    // MARK: - Properties

    /// Auth view model
    /// ViewModel Auth
    @StateObject private var viewModel = AuthViewModel()

    // MARK: - Body

    var body: some View {
        ZStack {
            // Background - Pastel Yellow Theme
            // Nền - Theme Pastel Vàng
            Color.appBackground
                .ignoresSafeArea()

            // Decorative gradient circles
            // Các vòng tròn gradient trang trí
            GeometryReader { geometry in
                Circle()
                    .fill(AppTheme.softGradient)
                    .frame(width: 300, height: 300)
                    .blur(radius: 60)
                    .offset(x: -100, y: -50)

                Circle()
                    .fill(Color.brandSecondary.opacity(0.2))
                    .frame(width: 200, height: 200)
                    .blur(radius: 40)
                    .offset(x: geometry.size.width - 100, y: geometry.size.height - 200)
            }
            .ignoresSafeArea()

            // Content
            // Nội dung
            VStack(spacing: 0) {
                // Current screen
                // Màn hình hiện tại
                switch viewModel.currentScreen {
                case .login:
                    LoginView(viewModel: viewModel)
                        .transition(.asymmetric(
                            insertion: .move(edge: .leading),
                            removal: .move(edge: .trailing)
                        ))
                case .register:
                    RegisterView(viewModel: viewModel)
                        .transition(.asymmetric(
                            insertion: .move(edge: .trailing),
                            removal: .move(edge: .leading)
                        ))
                case .forgotPassword:
                    ForgotPasswordView(viewModel: viewModel)
                        .transition(.asymmetric(
                            insertion: .move(edge: .trailing),
                            removal: .move(edge: .leading)
                        ))
                }
            }
        }
        .loadingOverlay(viewModel.isLoading)
    }
}

// MARK: - Preview

#Preview {
    AuthContainerView()
}
