//
//  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: 0) {
            HStack(spacing: 0) {
                Text(userId == UserDefaults.int(forKey: .userId) ? "내 콘텐츠" : "콘텐츠")
                    .font(.custom(Font.bold.rawValue, size: 18.3))
                    .foregroundColor(Color(hex: "eeeeee"))
                
                Spacer()
                
                Text("전체보기")
                    .font(.custom(Font.medium.rawValue, size: 12))
                    .foregroundColor(Color(hex: "bbbbbb"))
                    .onTapGesture {
                        AppState.shared.setAppStep(step: .contentListAll(userId: userId))
                    }
            }
            
            if userId == UserDefaults.int(forKey: .userId) {
                Text("새로운 콘텐츠 등록하기")
                    .font(.custom(Font.bold.rawValue, size: 15))
                    .foregroundColor(Color(hex: "eeeeee"))
                    .padding(.vertical, 17)
                    .frame(maxWidth: .infinity)
                    .background(Color(hex: "3bb9f1"))
                    .cornerRadius(5.3)
                    .padding(.top, 21)
                    .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)
                                )
                        }
                }
            }
            .padding(.top, 21)
        }
    }
}

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
                )
            ]
        )
    }
}