//
//  AuditionDetailRoleItemView.swift
//  SodaLive
//
//  Created by klaus on 1/6/25.
//

import SwiftUI
import Kingfisher

struct AuditionDetailRoleItemView: View {
    
    let item: GetAuditionRoleListData
    
    var body: some View {
        VStack(alignment: .leading, spacing: 10) {
            ZStack(alignment: .topLeading) {
                KFImage(URL(string: item.imageUrl))
                    .cancelOnDisappear(true)
                    .downsampling(size: CGSize(width: 1000, height: 350))
                    .resizable()
                    .aspectRatio(1000/350, contentMode: .fit)
                    .frame(maxWidth: .infinity)
                    .cornerRadius(6.7)
                    .overlay(
                        Color.black
                            .cornerRadius(6.7)
                            .opacity(item.isComplete ? 0.7 : 0.0)
                    )
                
                Text(item.isComplete ? "모집완료" : "모집중")
                    .font(.custom(Font.medium.rawValue, size: 13.3))
                    .foregroundColor(Color.white)
                    .padding(.horizontal, 9)
                    .padding(.vertical, 3)
                    .background(
                        item.isComplete ? Color.gray90 : Color.button
                    )
                    .cornerRadius(13.3)
                    .padding(.top, 7)
                    .padding(.leading, 7)
            }
            .frame(maxWidth: .infinity)
            
            Text(item.name)
                .font(.custom(Font.medium.rawValue, size: 13.3))
                .foregroundColor(Color.grayee)
                .lineLimit(1)
                .truncationMode(.tail)
        }
    }
}

#Preview {
    AuditionDetailRoleItemView(
        item: GetAuditionRoleListData(
            roleId: 1,
            name: "[남주] 김희준",
            imageUrl: "https://test-cf.sodalive.net/audition/role/7/audition_role-dc4174e1-10b5-4a97-8379-c7a9336ab230-6691-1735908236571",
            isComplete: false
        )
    )
}
