//
//  ContentMainNewContentViewV2.swift
//  SodaLive
//
//  Created by klaus on 2/21/25.
//

import SwiftUI

struct ContentMainNewContentViewV2: View {
    
    let title: String
    let onClickMore: () -> Void
    let themeList: [String]
    let contentList: [GetAudioContentMainItem]
    
    let selectTheme: (String) -> Void
    @State private var selectedTheme = "전체"
    
    var body: some View {
        LazyVStack(spacing: 13.3) {
            HStack(spacing: 0) {
                Text(title)
                    .font(.custom(Font.bold.rawValue, size: 18.3))
                    .foregroundColor(.grayee)
                
                Spacer()
                
                Image("ic_forward")
                    .resizable()
                    .frame(width: 20, height: 20)
                    .onTapGesture { onClickMore() }
            }
            .padding(.horizontal, 13.3)
            
            if !themeList.isEmpty {
                ContentMainContentThemeView(
                    themeList: themeList,
                    selectTheme: selectTheme,
                    selectedTheme: $selectedTheme
                )
            }
            
            ScrollView(.horizontal, showsIndicators: false) {
                HStack(spacing: 13.3) {
                    ForEach(0..<contentList.count, id: \.self) { index in
                        ContentMainItemView(item: contentList[index])
                    }
                }
                .padding(.horizontal, 13.3)
            }
        }
        .onAppear {
            if !themeList.isEmpty {
                selectedTheme = themeList[0]
            }
        }
    }
}

#Preview {
    ContentMainNewContentViewV2(
        title: "새로운 단편",
        onClickMore: {},
        themeList: ["전체", "테스트1", "테스트2"],
        contentList: [
            GetAudioContentMainItem(
                contentId: 1,
                coverImageUrl: "https://test-cf.sodalive.net/profile/default-profile.png",
                title: "ㅓ처랴햐햫햐햐",
                creatorId: 8,
                creatorProfileImageUrl: "https://test-cf.sodalive.net/profile/default-profile.png",
                creatorNickname: "유저1",
                price: 10,
                duration: "00:00:30"
            ),
            GetAudioContentMainItem(
                contentId: 2,
                coverImageUrl: "https://test-cf.sodalive.net/profile/default-profile.png",
                title: "ㅓ처랴햐햫햐햐",
                creatorId: 8,
                creatorProfileImageUrl: "https://test-cf.sodalive.net/profile/default-profile.png",
                creatorNickname: "유저2",
                price: 10,
                duration: "00:00:30"
            ),
            GetAudioContentMainItem(
                contentId: 3,
                coverImageUrl: "https://test-cf.sodalive.net/profile/default-profile.png",
                title: "ㅓ처랴햐햫햐햐",
                creatorId: 8,
                creatorProfileImageUrl: "https://test-cf.sodalive.net/profile/default-profile.png",
                creatorNickname: "유저3",
                price: 10,
                duration: "00:00:30"
            )
        ],
        selectTheme: { _ in }
    )
}