//
//  ContentMainNewContentView.swift
//  SodaLive
//
//  Created by klaus on 2023/08/11.
//

import SwiftUI

struct ContentMainNewContentView: View {
    
    @StateObject private var viewModel = ContentMainNewContentViewModel()
    
    var body: some View {
        VStack(spacing: 16.7) {
            HStack(spacing: 0) {
                Text("새로운 콘텐츠")
                    .font(.custom(Font.bold.rawValue, size: 18.3))
                    .foregroundColor(Color(hex: "eeeeee"))
                
                Spacer()
                
                Image("ic_forward")
                    .resizable()
                    .frame(width: 20, height: 20)
                    .onTapGesture {
                        AppState.shared.setAppStep(step: .newContentAll)
                    }
            }
            
            if !viewModel.themeList.isEmpty {
                ContentMainNewContentThemeView(
                    themes: viewModel.themeList,
                    selectTheme: { theme in
                        viewModel.selectedTheme = theme
                    },
                    selectedTheme: $viewModel.selectedTheme
                )
            }
            
            if !viewModel.newContentList.isEmpty {
                ScrollView(.horizontal, showsIndicators: false) {
                    LazyHStack(alignment: .top, spacing: 13.3) {
                        ForEach(0..<viewModel.newContentList.count, id: \.self) {
                            ContentMainItemView(item: viewModel.newContentList[$0])
                        }
                    }
                }
            }
            
            if viewModel.isLoading {
                ActivityIndicatorView()
                    .frame(width: 100, height: 100)
            }
        }
        .frame(maxWidth: .infinity)
        .onAppear {
            viewModel.getThemeList()
            viewModel.getNewContentOfTheme()
        }
    }
}

struct ContentMainNewContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentMainNewContentView()
    }
}