import SwiftUI

struct MainTabView: View {
    let container: AppContainer

    /// Owned here so a ride refusal that needs money can switch to the Wallet tab.
    @State private var selection = Tab.ride

    private enum Tab: Hashable { case ride, wallet, support }

    var body: some View {
        TabView(selection: $selection) {
            // The whole ride lifecycle lives behind RideFlowHost; HomeView is only
            // its idle surface.
            RideFlowHost(
                container: container,
                onTopUp: { selection = .wallet }
            ) { onScan in
                HomeView(
                    container: container,
                    onScan: onScan,
                    onTopUp: { selection = .wallet }
                )
            }
            .tabItem { Label("nav_ride".localized, systemImage: "scooter") }
            .tag(Tab.ride)

            WalletView(container: container)
                .tabItem { Label("nav_wallet".localized, systemImage: "creditcard") }
                .tag(Tab.wallet)

            SupportView(container: container)
                .tabItem { Label("nav_support".localized, systemImage: "bubble.left") }
                .tag(Tab.support)
        }
        .tint(.brand)
    }
}
