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

import SwiftUI

struct UserProfileContentView: View {
    
    let userId: Int
    let items: [GetAudioContentListItem]
    
    var body: some View {
        VStack(spacing: 21) {
            HStack(spacing: 0) {
                Text(userId == UserDefaults.int(forKey: .userId) ? "내 콘텐츠" : "콘텐츠")
                    .font(.custom(Font.bold.rawValue, size: 18.3))
                    .foregroundColor(Color.grayee)
                
                Spacer()
                
                Text("전체보기")
                    .font(.custom(Font.medium.rawValue, size: 12))
                    .foregroundColor(Color.graybb)
                    .onTapGesture {
                        AppState.shared.setAppStep(step: .contentListAll(userId: userId))
                    }
            }
            
            if userId == UserDefaults.int(forKey: .userId) {
                Text("새로운 콘텐츠 등록하기")
                    .font(.custom(Font.bold.rawValue, size: 15))
                    .foregroundColor(Color.grayee)
                    .padding(.vertical, 17)
                    .frame(maxWidth: .infinity)
                    .background(Color.button)
                    .cornerRadius(5.3)
                    .onTapGesture { AppState.shared.setAppStep(step: .createContent) }
            }
            
            VStack(spacing: 10.7) {
                ForEach(0..<items.count, id: \.self) { index in
                    let item = items[index]
                    ContentListItemView(item: item)
                        .contentShape(Rectangle())
                        .onTapGesture {
                            AppState
                                .shared
                                .setAppStep(
                                    step: .contentDetail(contentId: item.contentId)
                                )
                        }
                }
            }
        }
    }
}

struct UserProfileContentView_Previews: PreviewProvider {
    static var previews: some View {
        UserProfileContentView(
            userId: 0,
            items: [
                GetAudioContentListItem(
                    contentId: 25,
                    coverImageUrl: "https://test-cf.sodalive.net/profile/default-profile.png",
                    title: "폭우",
                    price: 110,
                    themeStr: "test",
                    duration: "00:04:43",
                    likeCount: 2,
                    commentCount: 0,
                    isPin: true,
                    isAdult: false,
                    isScheduledToOpen: false,
                    isRented: false,
                    isOwned: false,
                    isSoldOut: false
                )
            ]
        )
    }
}
