//
//  ContentPlaylistItemView.swift
//  SodaLive
//
//  Created by klaus on 12/7/24.
//

import SwiftUI
import Kingfisher

struct ContentPlaylistItemView: View {
    
    let item: GetPlaylistsItem
    
    var body: some View {
        VStack(alignment: .leading, spacing: 8) {
            HStack(spacing: 11) {
                KFImage(URL(string: item.coverImageUrl))
                    .cancelOnDisappear(true)
                    .downsampling(size: CGSize(width: 66.7, height: 66.7))
                    .resizable()
                    .scaledToFill()
                    .frame(width: 66.7, height: 66.7, alignment: .center)
                    .cornerRadius(5.3)
                    .clipped()
                
                VStack(alignment: .leading, spacing: 7) {
                    Text(item.title)
                        .font(.custom(Font.bold.rawValue, size: 14.7))
                        .foregroundColor(Color.grayd2)
                        .lineLimit(1)
                    
                    if !item.desc.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
                        Text(item.desc)
                            .font(.custom(Font.medium.rawValue, size: 12))
                            .foregroundColor(Color.gray90)
                            .lineLimit(1)
                    }
                    
                    Text("총 \(item.contentCount)개")
                        .font(.custom(Font.medium.rawValue, size: 12))
                        .foregroundColor(Color.gray90)
                        .lineLimit(1)
                }
            }
            
            Rectangle()
                .frame(height: 1)
                .foregroundColor(Color.gray55)
        }
    }
}

#Preview {
    ContentPlaylistItemView(
        item: GetPlaylistsItem(
            id: 1,
            title: "토스트",
            desc: "테슬라 네",
            contentCount: 2,
            coverImageUrl: "https://test-cf.sodalive.net/profile/default-profile.png"
        )
    )
}
