//
//  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) {
                    HStack(spacing: 0) {
                        Text("콘텐츠 마켓")
                            .font(.custom(Font.bold.rawValue, size: 21.3))
                            .foregroundColor(Color.button)
                        
                        Spacer()
                        
                        Image("ic_content_keep")
                            .onTapGesture {
                                AppState.shared.setAppStep(step: .orderListAll)
                            }
                    }
                    .padding(.bottom, 26.7)
                    .padding(.horizontal, 13.3)
                    
                    if !viewModel.isLoading {
                        ContentMainBannerView()
                            .padding(.bottom, 26.7)
                            .padding(.horizontal, 13.3)
                        
                        ContentMainRecommendSeriesView()
                        
                        HStack(spacing: 8) {
                            ZStack {
                                Image("img_bg_morning_call")
                                    .resizable()
                                    .frame(height: 53.3)
                                    .frame(maxWidth: .infinity)
                                    .cornerRadius(2.6)
                                
                                HStack(spacing: 2.7) {
                                    Image("ic_alarm_clock_blue")
                                    
                                    Text("보이스 모닝콜")
                                        .font(.custom(Font.bold.rawValue, size: 16.7))
                                        .foregroundColor(Color(hex: "0057ff"))
                                }
                                .cornerRadius(2.6)
                            }
                            .onTapGesture {
                                AppState.shared.setAppStep(
                                    step: .contentAllByTheme(themeId: 12)
                                )
                            }
                            
                            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)
                                )
                            }
                        }
                        .padding(.bottom, 40)
                        .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)
                        
                        Text("""
    - 회사명 : 주식회사 소다라이브
    
    - 대표자 : 이재형
    
    - 주소 : 경기도 성남시 분당구 황새울로335번길 10, 5층 563A호
    
    - 사업자등록번호 : 870-81-03220
    
    - 통신판매업신고 : 제2024-성남분당B-1012호
    
    - 고객센터 : 02.2055.1477 (이용시간 10:00~19:00)
    
    - 대표 이메일 : sodalive.official@gmail.com
    """)
                        .font(.custom(Font.medium.rawValue, size: 11))
                        .foregroundColor(Color.gray77)
                        .padding(.top, 13.3)
                        .padding(.horizontal, 13.3)
                    }
                }
                .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()
    }
}
