148 lines
		
	
	
		
			5.2 KiB
		
	
	
	
		
			Swift
		
	
	
	
	
	
			
		
		
	
	
			148 lines
		
	
	
		
			5.2 KiB
		
	
	
	
		
			Swift
		
	
	
	
	
	
import SwiftUI
 | 
						||
 | 
						||
struct ProfileTab: View {
 | 
						||
    @ObservedObject var viewModel: LoginViewModel
 | 
						||
//    @State private var selectedTabIndex = 0
 | 
						||
//    @State private var selectedSort = "По дате"
 | 
						||
//    @State private var selectedCategory = "#все"
 | 
						||
//    @State private var searchQuery = ""
 | 
						||
//    @State private var searchQueryArchive = ""
 | 
						||
//    @State private var searchQuerySaved = ""
 | 
						||
//    @State private var searchQueryLiked = ""
 | 
						||
    @State private var isContentLoaded = true
 | 
						||
 | 
						||
    @State private var accounts = ["@user1", "@user2", "@user3"]
 | 
						||
    @State private var selectedAccount = "@user1"
 | 
						||
    
 | 
						||
    let followers = ["@alice", "@bob", "@charlie"]
 | 
						||
    let following = ["@dev", "@design", "@ios"]
 | 
						||
    
 | 
						||
    @State private var sheetType: SheetType? = nil
 | 
						||
    enum SheetType: Identifiable {
 | 
						||
        case accountShare
 | 
						||
 | 
						||
        var id: Int {
 | 
						||
            switch self {
 | 
						||
            case .accountShare: return 1
 | 
						||
            }
 | 
						||
        }
 | 
						||
    }
 | 
						||
 | 
						||
    var body: some View {
 | 
						||
        NavigationView {
 | 
						||
            if !isContentLoaded{
 | 
						||
                SplashScreenView()
 | 
						||
            } else {
 | 
						||
            GeometryReader { geometry in
 | 
						||
                VStack(spacing: 0) {
 | 
						||
                    ScrollView {
 | 
						||
                        // ───── Шапка профиля (занимает ~50% экрана) ─────
 | 
						||
                        header
 | 
						||
                            .frame(minHeight: geometry.size.height * 0.5)
 | 
						||
                            .frame(maxWidth: .infinity)
 | 
						||
                            .background(Color(.systemBackground))
 | 
						||
 | 
						||
                        // ───── Скролл с контентом ─────
 | 
						||
                    
 | 
						||
                        ProfileContentTabbedGrid(isContentLoaded: isContentLoaded)
 | 
						||
                        
 | 
						||
                    }
 | 
						||
                    .frame(maxWidth: .infinity)
 | 
						||
                }
 | 
						||
                .frame(maxWidth: .infinity, maxHeight: .infinity)
 | 
						||
            }
 | 
						||
            .navigationBarTitleDisplayMode(.inline)
 | 
						||
            .toolbar {
 | 
						||
                ToolbarItem(placement: .principal) {
 | 
						||
                    Button(action: {
 | 
						||
                        sheetType = .accountShare
 | 
						||
                    }) {
 | 
						||
                        HStack(spacing: 4) {
 | 
						||
                            Text("custom_user_name")
 | 
						||
                                .font(.headline)
 | 
						||
                                .foregroundColor(.primary)
 | 
						||
                            Image(systemName: "chevron.down")
 | 
						||
                                .font(.subheadline)
 | 
						||
                                .foregroundColor(.gray)
 | 
						||
                        }
 | 
						||
                    }
 | 
						||
                }
 | 
						||
 | 
						||
                ToolbarItem(placement: .navigationBarTrailing) {
 | 
						||
                    NavigationLink(destination: SettingsView(viewModel: viewModel)) {
 | 
						||
                        Image(systemName: "wrench")
 | 
						||
                            .imageScale(.large)
 | 
						||
                    }
 | 
						||
                }
 | 
						||
            }
 | 
						||
            .sheet(item: $sheetType) { type in
 | 
						||
                switch type {
 | 
						||
                case .accountShare:
 | 
						||
                    AccountShareSheet(
 | 
						||
                        isPresented: Binding(
 | 
						||
                            get: { sheetType != nil },
 | 
						||
                            set: { if !$0 { sheetType = nil } }
 | 
						||
                        ),
 | 
						||
                        selectedAccount: $selectedAccount,
 | 
						||
                        accounts: accounts
 | 
						||
                    )
 | 
						||
                }
 | 
						||
            }
 | 
						||
        }
 | 
						||
        }
 | 
						||
        .navigationViewStyle(StackNavigationViewStyle())
 | 
						||
//        .onAppear {
 | 
						||
//            if !isContentLoaded {
 | 
						||
//                DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
 | 
						||
//                    isContentLoaded = true
 | 
						||
//                }
 | 
						||
//            }
 | 
						||
//        }
 | 
						||
    }
 | 
						||
 | 
						||
    // MARK: - Шапка профиля
 | 
						||
    private var header: some View {
 | 
						||
        VStack(spacing: 12) {
 | 
						||
            // Аватар и имя
 | 
						||
            VStack(spacing: 6) {
 | 
						||
                Image(systemName: "person.crop.circle.fill")
 | 
						||
                    .resizable()
 | 
						||
                    .frame(width: 72, height: 72)
 | 
						||
                    .foregroundColor(.gray)
 | 
						||
 | 
						||
                Text(selectedAccount)
 | 
						||
                    .font(.headline)
 | 
						||
            }
 | 
						||
            .padding(.top, 16)
 | 
						||
 | 
						||
            Text("iOS разработчик, делаю интерфейсы, иногда снимаю блоги и делюсь кодом. Всегда рад новым подписчикам и интересным проектам.")
 | 
						||
                .font(.subheadline)
 | 
						||
                .foregroundColor(.secondary)
 | 
						||
                .multilineTextAlignment(.center)
 | 
						||
                .padding(.horizontal)
 | 
						||
 | 
						||
            // Статистика
 | 
						||
            HStack(spacing: 32) {
 | 
						||
                statView("24", "Посты")
 | 
						||
                NavigationLink(destination: FollowersView(followers: followers)) {
 | 
						||
                    statView("1.2k", "Подписчики")
 | 
						||
                }
 | 
						||
                NavigationLink(destination: FollowingView(following: following)) {
 | 
						||
                    statView("156", "Подписки")
 | 
						||
                }
 | 
						||
            }
 | 
						||
        }
 | 
						||
        .padding(.horizontal)
 | 
						||
    }
 | 
						||
 | 
						||
    // MARK: - Статистика
 | 
						||
    func statView(_ value: String, _ label: String) -> some View {
 | 
						||
        VStack {
 | 
						||
            Text(value)
 | 
						||
                .font(.headline)
 | 
						||
            Text(label)
 | 
						||
                .font(.caption)
 | 
						||
        }
 | 
						||
    }
 | 
						||
}
 |