//
//  PlaylistContentItemView.swift
//  SodaLive
//
//  Created by klaus on 12/10/24.
//

import SwiftUI
import Kingfisher

struct PlaylistContentItemView: View {
    
    let item: AudioContentPlaylistContent
    
    var body: some View {
        HStack(spacing: 13.3) {
            KFImage(URL(string: item.coverUrl))
                .cancelOnDisappear(true)
                .downsampling(size: CGSize(width: 40, height: 40))
                .resizable()
                .scaledToFill()
                .frame(width: 40, height: 40, alignment: .center)
                .cornerRadius(5.3)
                .clipped()
                .padding(.vertical, 7.5)
            
            VStack(alignment: .leading, spacing: 2.6) {
                HStack(spacing: 8) {
                    Text(item.category)
                        .font(.custom(Font.medium.rawValue, size: 10))
                        .foregroundColor(Color(hex: "3bac6a"))
                        .padding(2.6)
                        .background(Color(hex: "28312b"))
                        .cornerRadius(2.6)
                    
                    Text(item.duration)
                        .font(.custom(Font.medium.rawValue, size: 10))
                        .foregroundColor(Color.gray77)
                        .padding(2.6)
                        .background(Color.gray22)
                        .cornerRadius(2.6)
                }
                
                Text(item.title)
                    .font(.custom(Font.medium.rawValue, size: 12))
                    .foregroundColor(Color.grayd2)
                    .lineLimit(2)
                    .truncationMode(.tail)
            }
            
            Spacer()
        }
    }
}

#Preview {
    PlaylistContentItemView(
        item: AudioContentPlaylistContent(
            id: 1,
            title: "안녕하세요 오늘은 커버곡을 들려드릴께요....안녕하세요 오늘은 커버곡을 들려드릴께요....",
            category: "커버곡",
            coverUrl: "https://test-cf.sodalive.net/profile/default-profile.png",
            duration: "00:30:20",
            creatorNickname: "유저1",
            creatorProfileUrl: "https://test-cf.sodalive.net/profile/default-profile.png"
        )
    )
}
