import SwiftUI

struct MainAppView: View {
    @EnvironmentObject var viewModel: PDSViewModel
    @State private var selectedTab = 0
    
    var body: some View {
        ZStack {
            if viewModel.isAuthenticated {
                authenticatedView
            } else {
                LoginView()
            }
        }
        .alert(item: $viewModel.alertItem) { alert in
            Alert(
                title: Text(alert.title),
                message: Text(alert.message),
                dismissButton: .default(Text("OK"))
            )
        }
    }
    
    var authenticatedView: some View {
        NavigationView {
            TabView(selection: $selectedTab) {
                InviteCodesView()
                    .tabItem {
                        Image(systemName: "ticket")
                        Text("Invite Codes")
                    }
                    .tag(0)
                
                UserListView()
                    .tabItem {
                        Image(systemName: "person.3")
                        Text("Users")
                    }
                    .tag(1)
            }
            .navigationTitle("PDS Manager")
            .navigationBarItems(trailing: Button("Logout") {
                viewModel.logout()
            })
        }
        .onAppear {
            print("Authenticated view appeared")
        }
    }
} 