//
//  ContentMainView.swift
//  SodaLive
//
//  Created by klaus on 2023/08/09.
//

import SwiftUI

struct ContentMainView: View {
    
    @StateObject var viewModel = ContentMainViewModel()
    
    var body: some View {
        ZStack(alignment: .bottomTrailing) {
            Color.black.ignoresSafeArea()
            
            ScrollView(.vertical, showsIndicators: false) {
                VStack(alignment: .leading, spacing: 0) {
                    Text("콘텐츠 마켓")
                        .font(.custom(Font.bold.rawValue, size: 21.3))
                        .foregroundColor(Color(hex: "3bb9f1"))
                        .padding(.bottom, 26.7)
                        .padding(.horizontal, 13.3)
                    
                    if !viewModel.isLoading {
                        ContentMainRecommendSeriesView()
                        
                        ContentMainBannerView()
                            .padding(.bottom, 26.7)
                            .padding(.horizontal, 13.3)
                        
                        HStack(spacing: 8) {
                            ZStack {
                                Image("img_bg_short_play")
                                    .resizable()
                                    .frame(height: 53.3)
                                    .frame(maxWidth: .infinity)
                                    .cornerRadius(2.6)
                                
                                HStack(spacing: 2.7) {
                                    Image("ic_short_play")
                                    
                                    Text("숏플")
                                        .font(.custom(Font.bold.rawValue, size: 16.7))
                                        .foregroundColor(Color(hex: "dd158d"))
                                }
                                .cornerRadius(2.6)
                            }
                            .onTapGesture {
                                AppState.shared.setAppStep(
                                    step: .contentAllByTheme(themeId: 11)
                                )
                            }
                            
                            ZStack {
                                Image("img_bg_review_live")
                                    .resizable()
                                    .frame(height: 53.3)
                                    .frame(maxWidth: .infinity)
                                    .cornerRadius(2.6)
                                
                                HStack(spacing: 2.7) {
                                    Image("ic_thumb_play_blue")
                                    
                                    Text("라이브 다시듣기")
                                        .font(.custom(Font.bold.rawValue, size: 16.7))
                                        .foregroundColor(Color(hex: "0057ff"))
                                }
                                .cornerRadius(2.6)
                            }
                            .onTapGesture {
                                AppState.shared.setAppStep(
                                    step: .contentAllByTheme(themeId: 7)
                                )
                            }
                        }
                        .padding(.bottom, 40)
                        .padding(.horizontal, 13.3)
                        
                        ContentMainMyStashView()
                            .padding(.horizontal, 13.3)
                        
                        ContentMainNewContentView()
                            .padding(.horizontal, 13.3)
                        
                        ContentMainRankingView()
                            .padding(.top, 40)
                            .padding(.horizontal, 13.3)
                            .animation(nil)
                        
                        ContentMainCurationView()
                            .padding(.top, 40)
                            .padding(.bottom, 20)
                    }
                }
                .padding(.vertical, 13.3)
            }
            
            if UserDefaults.string(forKey: .role) == MemberRole.CREATOR.rawValue {
                HStack(spacing: 5) {
                    Image("ic_thumb_play")
                        .resizable()
                        .frame(width: 20, height: 20)
                    
                    Text("콘텐츠 업로드")
                        .font(.custom(Font.bold.rawValue, size: 13.3))
                        .foregroundColor(.white)
                }
                .padding(13.3)
                .background(Color(hex: "3bb9f1"))
                .cornerRadius(44)
                .padding(.trailing, 16.7)
                .padding(.bottom, 16.7)
                .onTapGesture {
                    AppState.shared.setAppStep(step: .createContent)
                }
            }
        }
        
        if viewModel.isLoading {
            LoadingView()
        }
    }
}

struct ContentMainView_Previews: PreviewProvider {
    static var previews: some View {
        ContentMainView()
    }
}