//
//  AuditionApplicantItemView.swift
//  SodaLive
//
//  Created by klaus on 1/7/25.
//

import SwiftUI
import Kingfisher

struct AuditionApplicantItemView: View {
    
    let item: GetAuditionRoleApplicantItem
    
    var body: some View {
        VStack(spacing: 5.3) {
            HStack(spacing: 13.3) {
                ZStack {
                    KFImage(URL(string: item.profileImageUrl))
                        .cancelOnDisappear(true)
                        .downsampling(size: CGSize(width: 40, height: 40))
                        .resizable()
                        .aspectRatio(1, contentMode: .fit)
                        .scaledToFill()
                        .frame(width: 40, height: 40)
                        .clipShape(Circle())
                    
                    Image("ic_audition_play")
                        .onTapGesture {
                        }
                }
                
                VStack(spacing: 8) {
                    HStack(spacing: 0) {
                        Text(item.nickname.count > 9 ? "\(item.nickname.prefix(9))..." : item.nickname)
                            .font(.custom(Font.medium.rawValue, size: 12))
                            .foregroundColor(Color.white)
                        
                        Spacer()
                    }
                }
                
                VStack(spacing: 2.3) {
                    Image("ic_heart_vote")
                    
                    Text("\(item.voteCount)")
                        .font(.custom(Font.medium.rawValue, size: 12))
                        .foregroundColor(Color.gray77)
                }
            }
            .padding(.vertical, 18.7)
            
            Color.gray55
                .frame(maxWidth: .infinity)
                .frame(height: 1)
        }
        .padding(.horizontal, 13.3)
    }
}

#Preview {
    AuditionApplicantItemView(
        item: GetAuditionRoleApplicantItem(
            applicantId: 1,
            memberId: 2,
            nickname: "유저일유저일유저일유저일",
            profileImageUrl: "https://test-cf.sodalive.net/profile/default-profile.png",
            voiceUrl: "",
            voteCount: 777
        )
    )
}
