//
//  TabBarView.swift
//  jason
//
//  Created by Jason on 2024/1/19.
//

import SwiftUI

struct TabBarView: View {
    @AppStorage("selectedTab") var selectedTab : Tab = .home
    
    var body: some View {
        ZStack(alignment: .leading) {
            Group {
                switch selectedTab {
                case .home:
                    HomeView()
                case .explore:
                    MallView()
                case .message:
                    MessageView()
                case .account:
                    UserView()
                }
            }
//            .offset(y: -44)
//            .safeAreaInset(edge: .top) {
//                Color.clear.frame(height: 32)
//            }

            HStack {
                ForEach(tabItems) { item in
                    Button(action: {
                        selectedTab = item.tab
                    }, label: {
                        VStack (spacing: 6) {
                            Image(systemName: item.icon).resizable().frame(width: 18, height: 18)
                            Text(item.text)
                                .font(.caption)
                                .fontWeight(.regular)
                                .multilineTextAlignment(.center)
                                .lineLimit(1)
                        }
                        .frame(maxWidth: .infinity)
                    })
                    .foregroundColor(selectedTab == item.tab ? Color("MainText") : Color.secondary)
                    .shadow(color: (selectedTab == item.tab ? Color.orange: Color.blue), radius: 15)
                }
            }
            .padding(.top, 12.0)
            .padding(.bottom, 32)
            .background(Color("TabBarColor"))
            .frame(maxHeight: .infinity, alignment: .bottom)
            .shadow(color: Color.gray.opacity(0.5), radius: 6, x: 0, y: 6)
            .ignoresSafeArea()
        }
        .statusBarHidden(false)
    }
}

#Preview {
    TabBarView()
}

