import SwiftUI

/// 主界面：未连接时显示设置面板，连接成功后显示远程控制面板。
struct ContentView: View {
    @StateObject private var viewModel = ControllerViewModel()

    var body: some View {
        ZStack {
            if !viewModel.isLoggedIn {
                LoginView(viewModel: viewModel)
            } else if viewModel.isControlling {
                ControlPanelView(viewModel: viewModel)
            } else {
                SetupPanelView(viewModel: viewModel)
            }
        }
        .sheet(isPresented: $viewModel.showAuthSheet) {
            AuthSheetView { authType, authValue in
                viewModel.connect(authType: authType, authValue: authValue)
            }
        }
        .alert("提示", isPresented: Binding(
            get: { viewModel.alertMessage != nil },
            set: { if !$0 { viewModel.alertMessage = nil } })) {
            Button("确定", role: .cancel) { viewModel.alertMessage = nil }
        } message: {
            Text(viewModel.alertMessage ?? "")
        }
    }
}
