import SwiftUI

struct ContentView: View {
    @EnvironmentObject var viewModel: CallViewModel
    
    var body: some View {
        Group {
            if viewModel.currentUser == nil {
                LoginView()
            } else {
                switch viewModel.callState.status {
                case .incoming:
                    IncomingCallView()
                case .inCall, .connecting:
                    CallView()
                default:
                    DashboardView()
                }
            }
        }
        .overlay(
            Group {
                if let error = viewModel.errorMessage {
                    VStack {
                        Text(error)
                            .foregroundColor(.red)
                            .padding()
                            .background(Color(UIColor.systemBackground))
                            .cornerRadius(10)
                            .shadow(radius: 5)
                    }
                    .padding()
                    .transition(.move(edge: .top))
                    .onAppear {
                        DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
                            viewModel.errorMessage = nil
                        }
                    }
                }
            }, alignment: .top
        )
    }
}
