import SwiftUI struct MainTabView: View { @Binding var selectedTab: MainTab @Binding var root: RootFlow let tokenStore: TokenStore @Binding var appState: AppState var body: some View { ZStack(alignment: .bottom) { Group { switch selectedTab { case .home: NavigationStack { HomeView(appState: $appState, selectedTab: $selectedTab) } case .cart: NavigationStack { CartView(appState: $appState) } case .profile: NavigationStack { ProfileView(root: $root, selectedTab: $selectedTab, tokenStore: tokenStore, appState: $appState) } } } customTabBar } } private var customTabBar: some View { HStack(spacing: 12) { tabBarButton(tab: .home, title: "Home", icon: "house.fill") tabBarButton(tab: .cart, title: "Carrinho", icon: "cart.fill", badgeCount: appState.cart.totalItems) tabBarButton(tab: .profile, title: "Perfil", icon: "person.fill") } .padding(.horizontal, 14) .padding(.vertical, 10) .background( RoundedRectangle(cornerRadius: 30, style: .continuous) .fill(AppColors.surface.opacity(0.95)) ) .padding(.horizontal, 18) .padding(.bottom, 10) .shadow(color: AppShadow.soft.color, radius: AppShadow.soft.radius, y: AppShadow.soft.y) } private func tabBarButton(tab: MainTab, title: String, icon: String, badgeCount: Int = 0) -> some View { let isActive = selectedTab == tab return Button { selectedTab = tab } label: { HStack(spacing: 8) { ZStack(alignment: .topTrailing) { Image(systemName: icon) .font(.system(size: 18, weight: .semibold)) if badgeCount > 0 { Text("\(min(badgeCount, 99))") .font(.system(size: 9, weight: .bold)) .foregroundStyle(Color.white) .padding(.horizontal, 4) .padding(.vertical, 2) .background(Color.red) .clipShape(Capsule()) .offset(x: 9, y: -8) } } if isActive { Text(title) .font(AppTypography.heading3) } } .foregroundStyle(isActive ? AppColors.textInverse : AppColors.textPrimary) .padding(.horizontal, 18) .padding(.vertical, 10) .background( Capsule() .fill(isActive ? AppColors.primary : Color.clear) ) } .buttonStyle(.plain) } }