Files
pos-system/microservices/apps/app-client-base-swift/AppClientBaseSwift/AppClientBaseSwift/ContentView.swift
Ho Ngoc Hai 76d75c753b Migrate
2026-05-23 18:37:02 +07:00

199 lines
5.3 KiB
Swift

//
// ContentView.swift
// AppClientBaseSwift
//
// Main tab container with TabView
// Container tab chính vi TabView
//
import SwiftUI
// MARK: - Content View
// View Content
/// Main content view with tab-based navigation
/// View content chính vi điu hưng tab
struct ContentView: View {
// MARK: - Properties
/// Currently selected tab
/// Tab đang đưc chn
@State private var selectedTab: Tab = .home
/// Auth manager for authentication state
/// Qun lý xác thc cho trng thái authentication
@StateObject private var authManager = AuthManager.shared
/// Whether to show welcome screen
/// Có hin th màn hình welcome không
@AppStorage(StorageKeys.isFirstLaunch) private var isFirstLaunch: Bool = true
// MARK: - Tab Enum
/// Available tabs
/// Các tab có sn
enum Tab: String, CaseIterable {
case home
case explore
case profile
/// Tab title
/// Tiêu đ tab
var title: String {
switch self {
case .home:
return "tab_home".localized
case .explore:
return "tab_explore".localized
case .profile:
return "tab_profile".localized
}
}
/// Tab icon
/// Icon tab
var icon: String {
switch self {
case .home:
return "house"
case .explore:
return "magnifyingglass"
case .profile:
return "person"
}
}
/// Selected tab icon
/// Icon tab khi đưc chn
var selectedIcon: String {
switch self {
case .home:
return "house.fill"
case .explore:
return "magnifyingglass"
case .profile:
return "person.fill"
}
}
}
// MARK: - Body
var body: some View {
Group {
switch authManager.authState {
case .unknown:
// Show loading while checking auth state
// Hin th loading khi đang kim tra trng thái auth
loadingView
case .unauthenticated:
// Show auth flow
// Hin th lung auth
AuthContainerView()
case .authenticated:
// Show main app content
// Hin th ni dung app chính
if isFirstLaunch {
WelcomeView {
withAnimation {
isFirstLaunch = false
}
}
} else {
mainTabView
}
}
}
.task {
await authManager.initialize()
}
}
// MARK: - Subviews
/// Loading view while checking auth
/// View loading khi đang kim tra auth
private var loadingView: some View {
ZStack {
Color.appBackground
.ignoresSafeArea()
VStack(spacing: 16) {
// App logo
ZStack {
Circle()
.fill(AppTheme.primaryGradient)
.frame(width: 80, height: 80)
Image(systemName: "location.fill")
.font(.system(size: 32))
.foregroundStyle(Color.textPrimary)
}
.shadow(color: AppTheme.cardShadow, radius: 20, x: 0, y: 10)
ProgressView()
.scaleEffect(1.2)
.tint(Color.brandAccent)
}
}
}
// MARK: - Subviews
/// Main tab view container
/// Container tab view chính
private var mainTabView: some View {
TabView(selection: $selectedTab) {
// Home Tab
// Tab Home
HomeView()
.tabItem {
Label {
Text(Tab.home.title)
} icon: {
Image(
systemName: selectedTab == .home ? Tab.home.selectedIcon : Tab.home.icon
)
}
}
.tag(Tab.home)
// Explore Tab
// Tab Khám phá
ExploreView()
.tabItem {
Label {
Text(Tab.explore.title)
} icon: {
Image(
systemName: selectedTab == .explore
? Tab.explore.selectedIcon : Tab.explore.icon)
}
}
.tag(Tab.explore)
// Profile Tab
// Tab Profile
ProfileView()
.tabItem {
Label {
Text(Tab.profile.title)
} icon: {
Image(
systemName: selectedTab == .profile
? Tab.profile.selectedIcon : Tab.profile.icon)
}
}
.tag(Tab.profile)
}
.tint(Color.brandAccent)
}
}
// MARK: - Preview
#Preview {
ContentView()
}