// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown // SPDX-License-Identifier: GPL-3.0-or-later import SwiftUI /// Sizzle's four tabs (Tracker, Mix, Toolbox, Setup) with a bottom bar in /// portrait and a side rail in landscape, as the Android app's App.kt lays them out. struct RootView: View { @ObservedObject private var app: AppModel init(model: AppModel? = nil) { app = model ?? AppModel.main } @Environment(\.scenePhase) private var phase @Environment(\.verticalSizeClass) private var vClass var body: some View { GeometryReader { geo in let landscape = geo.size.width > geo.size.height Group { if landscape { HStack(spacing: 0) { rail; Divider().background(Theme.grid); screen } } else { VStack(spacing: 0) { screen; Divider().background(Theme.grid); bar } } } .background(Theme.background.ignoresSafeArea()) } .environmentObject(app) .preferredColorScheme(.dark) .onChange(of: phase) { p in if p != .active { app.session.autosave() } } } @ViewBuilder private var screen: some View { Group { switch app.tab { case .tracker: TrackerScreen() case .mix: MixScreen() case .toolbox: ToolboxScreen() case .setup: SetupScreen() } } .frame(maxWidth: .infinity, maxHeight: .infinity) } private let tabs: [(AppModel.Tab, String, String)] = [ (.tracker, "Tracker", "square.grid.3x3"), (.mix, "Mix", "slider.vertical.3"), (.toolbox, "Toolbox", "square.grid.2x2"), (.setup, "Setup", "gearshape"), ] private var bar: some View { HStack { ForEach(tabs, id: \.0) { t in tabButton(t).frame(maxWidth: .infinity) } } .padding(.vertical, 6) .background(Theme.surface) } private var rail: some View { VStack(spacing: 18) { ForEach(tabs, id: \.0) { t in tabButton(t) } Spacer() } .padding(.top, 16).frame(width: 84) .background(Theme.surface) } private func tabButton(_ t: (AppModel.Tab, String, String)) -> some View { let on = app.tab == t.0 return VStack(spacing: 3) { Image(systemName: t.2).font(.system(size: 18)) .frame(width: 56, height: 30) .background(on ? Theme.accent : Color.clear, in: Capsule()) .foregroundColor(on ? Theme.background : Theme.dim) Text(t.1).font(.system(size: 12, weight: on ? .bold : .regular)).foregroundColor(on ? Theme.accent : Theme.dim) } .contentShape(Rectangle()) .onTapGesture { app.tab = t.0 } } }