116 lines
		
	
	
		
			4.4 KiB
		
	
	
	
		
			Swift
		
	
	
	
	
	
			
		
		
	
	
			116 lines
		
	
	
		
			4.4 KiB
		
	
	
	
		
			Swift
		
	
	
	
	
	
//
 | 
						|
//  CharacterView.swift
 | 
						|
//  SodaLive
 | 
						|
//
 | 
						|
//  Created by klaus on 8/29/25.
 | 
						|
//
 | 
						|
 | 
						|
import SwiftUI
 | 
						|
 | 
						|
struct CharacterView: View {
 | 
						|
    @StateObject var viewModel = CharacterViewModel()
 | 
						|
    
 | 
						|
    private let horizontalPadding: CGFloat = 16
 | 
						|
    
 | 
						|
    let onSelectCharacter: (Int) -> Void
 | 
						|
    
 | 
						|
    var body: some View {
 | 
						|
        BaseView(isLoading: $viewModel.isLoading) {
 | 
						|
            ScrollView(.vertical, showsIndicators: false) {
 | 
						|
                VStack(alignment: .leading, spacing: 48) {
 | 
						|
                    // 배너
 | 
						|
                    if !viewModel.banners.isEmpty {
 | 
						|
                        AutoSlideCharacterBannerView(items: viewModel.banners) { banner in
 | 
						|
                            onSelectCharacter(banner.characterId)
 | 
						|
                        }
 | 
						|
                    }
 | 
						|
                    
 | 
						|
                    // 최근 대화한 캐릭터 섹션
 | 
						|
                    if !viewModel.recentCharacters.isEmpty {
 | 
						|
                        RecentCharacterSectionView(
 | 
						|
                            titleCount: viewModel.recentCharacters.count,
 | 
						|
                            items: viewModel.recentCharacters
 | 
						|
                        ) { ch in
 | 
						|
                            onSelectCharacter(ch.characterId)
 | 
						|
                        }
 | 
						|
                    }
 | 
						|
                    
 | 
						|
                    // 인기 캐릭터 섹션
 | 
						|
                    if !viewModel.popularCharacters.isEmpty {
 | 
						|
                        CharacterSectionView(
 | 
						|
                            title: "인기 캐릭터",
 | 
						|
                            items: viewModel.popularCharacters,
 | 
						|
                            isShowRank: true,
 | 
						|
                            onTap: { ch in
 | 
						|
                                onSelectCharacter(ch.characterId)
 | 
						|
                            }
 | 
						|
                        )
 | 
						|
                    }
 | 
						|
                    
 | 
						|
                    // 신규 캐릭터 섹션
 | 
						|
                    if !viewModel.newCharacters.isEmpty {
 | 
						|
                        CharacterSectionView(
 | 
						|
                            title: "신규 캐릭터",
 | 
						|
                            items: viewModel.newCharacters,
 | 
						|
                            isShowRank: false,
 | 
						|
                            trailingTitle: "전체보기",
 | 
						|
                            onTapTrailing: {
 | 
						|
                                AppState.shared
 | 
						|
                                    .setAppStep(step: .newCharacterAll)
 | 
						|
                            },
 | 
						|
                            onTap: { ch in
 | 
						|
                                onSelectCharacter(ch.characterId)
 | 
						|
                            }
 | 
						|
                        )
 | 
						|
                    }
 | 
						|
                    
 | 
						|
                    // 큐레이션 섹션 (여러 섹션)
 | 
						|
                    if !viewModel.curations.isEmpty {
 | 
						|
                        VStack(alignment: .leading, spacing: 48) {
 | 
						|
                            ForEach(viewModel.curations.indices, id: \.self) { idx in
 | 
						|
                                let section = viewModel.curations[idx]
 | 
						|
                                CharacterSectionView(
 | 
						|
                                    title: section.title,
 | 
						|
                                    items: section.characters,
 | 
						|
                                    isShowRank: false,
 | 
						|
                                    onTap: { ch in
 | 
						|
                                        onSelectCharacter(ch.characterId)
 | 
						|
                                    }
 | 
						|
                                )
 | 
						|
                            }
 | 
						|
                        }
 | 
						|
                    }
 | 
						|
                }
 | 
						|
                .padding(.bottom, 24)
 | 
						|
            }
 | 
						|
            .background(Color.black.ignoresSafeArea())
 | 
						|
            .onAppear {
 | 
						|
                if !viewModel.isLoading {
 | 
						|
                    viewModel.getCharacterMain()
 | 
						|
                }
 | 
						|
            }
 | 
						|
        }
 | 
						|
        .popup(isPresented: $viewModel.isShowPopup, type: .toast, position: .top, autohideIn: 2) {
 | 
						|
            GeometryReader { geo in
 | 
						|
                HStack {
 | 
						|
                    Spacer()
 | 
						|
                    Text(viewModel.errorMessage)
 | 
						|
                        .padding(.vertical, 13.3)
 | 
						|
                        .frame(width: geo.size.width - 66.7, alignment: .center)
 | 
						|
                        .font(.custom(Font.medium.rawValue, size: 12))
 | 
						|
                        .background(Color.button)
 | 
						|
                        .foregroundColor(Color.white)
 | 
						|
                        .multilineTextAlignment(.center)
 | 
						|
                        .cornerRadius(20)
 | 
						|
                        .padding(.top, 66.7)
 | 
						|
                    Spacer()
 | 
						|
                }
 | 
						|
            }
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
#Preview {
 | 
						|
    CharacterView(onSelectCharacter: { _ in })
 | 
						|
}
 |