import SwiftUI private enum mlbIOSSection: String, CaseIterable, Identifiable { case games case league case multiView case settings var id: String { rawValue } var title: String { switch self { case .games: "Games" case .league: "League" case .multiView: "Multi-View" case .settings: "Settings" } } var systemImage: String { switch self { case .games: "sportscourt.fill" case .league: "list.bullet.rectangle.portrait.fill" case .multiView: "rectangle.split.2x2.fill" case .settings: "gearshape.fill" } } } struct mlbIOSRootView: View { @Environment(GamesViewModel.self) private var viewModel @Environment(\.horizontalSizeClass) private var horizontalSizeClass @State private var selectedSection: mlbIOSSection? = .games private var usesCompactTabs: Bool { horizontalSizeClass == .compact } private var multiViewTitle: String { let count = viewModel.activeStreams.count return count > 0 ? "Multi-View (\(count))" : "Multi-View" } var body: some View { Group { if usesCompactTabs { compactTabs } else { splitView } } .task { if viewModel.games.isEmpty, !viewModel.isLoading { await viewModel.loadGames() } } } private var compactTabs: some View { TabView { Tab("Games", systemImage: "sportscourt.fill") { DashboardView() } Tab("League", systemImage: "list.bullet.rectangle.portrait.fill") { LeagueCenterView() } Tab(multiViewTitle, systemImage: "rectangle.split.2x2.fill") { MultiStreamView() } Tab("Settings", systemImage: "gearshape.fill") { SettingsView() } } } private var splitView: some View { NavigationSplitView { List(mlbIOSSection.allCases, selection: $selectedSection) { section in Label(section.title, systemImage: section.systemImage) .tag(section) } .navigationTitle("MLB") } detail: { NavigationStack { detailView(for: selectedSection ?? .games) .navigationTitle(selectedSection?.title ?? mlbIOSSection.games.title) .navigationBarTitleDisplayMode(.inline) } } .navigationSplitViewStyle(.balanced) } @ViewBuilder private func detailView(for section: mlbIOSSection) -> some View { switch section { case .games: DashboardView() case .league: LeagueCenterView() case .multiView: MultiStreamView() case .settings: SettingsView() } } }