//
//  LiveNowAllItemView.swift
//  SodaLive
//
//  Created by klaus on 2023/08/14.
//

import SwiftUI
import Kingfisher

struct LiveNowAllItemView: View {
    
    let item: GetRoomListResponse
    
    var body: some View {
        VStack(spacing: 13.3) {
            HStack(spacing: 20) {
                ZStack(alignment: .topLeading) {
                    KFImage(URL(string: item.coverImageUrl))
                        .resizable()
                        .scaledToFill()
                        .frame(width: 80, height: 116.7, alignment: .top)
                        .cornerRadius(4.7)
                        .clipped()
                }
                
                VStack(alignment: .leading, spacing: 0) {
                    HStack(alignment: .top, spacing: 0) {
                        VStack(alignment: .leading, spacing: 0) {
                            Text(item.creatorNickname)
                                .font(.custom(Font.medium.rawValue, size: 11.3))
                                .foregroundColor(Color(hex: "bbbbbb"))
                            
                            Text(item.title)
                                .font(.custom(Font.medium.rawValue, size: 15.3))
                                .foregroundColor(Color(hex: "e2e2e2"))
                                .lineLimit(2)
                                .padding(.top, 4.3)
                                .padding(.trailing, 20)
                        }
                        
                        Spacer()
                        
                        if item.isPrivateRoom {
                            Image("ic_lock")
                                .resizable()
                                .frame(width: 20, height: 20)
                        }
                    }
                    .padding(.top, 13.3)
                    
                    Spacer()
                    
                    HStack(spacing: 0) {
                        Image("ic_avatar")
                            .resizable()
                            .frame(width: 20, height: 20)
                        
                        Text("\(item.numberOfParticipate)")
                            .font(.custom(Font.medium.rawValue, size: 13.3))
                            .foregroundColor(.white)
                            .padding(.leading, 2.7)
                        
                        Text("/\(item.numberOfPeople)")
                            .font(.custom(Font.medium.rawValue, size: 13.3))
                            .foregroundColor(Color(hex: "555555"))
                        
                        Text(item.numberOfPeople > item.numberOfParticipate ? "참여가능" : "Sold out")
                            .font(.custom(Font.medium.rawValue, size: 13.3))
                            .foregroundColor(
                                Color(
                                    hex: item.numberOfPeople > item.numberOfParticipate ?
                                    "9970ff" :
                                        "ffd300"
                                )
                            )
                            .padding(.leading, 10)
                        
                        Spacer()
                        
                        if item.price > 0 {
                            Text("\(item.price)")
                                .font(.custom(Font.bold.rawValue, size: 15.3))
                                .foregroundColor(Color(hex: "eeeeee"))
                            
                            Image("ic_can")
                                .resizable()
                                .frame(width: 20, height: 20)
                                .padding(.leading, 6.7)
                        } else {
                            Text("무료")
                                .font(.custom(Font.bold.rawValue, size: 15.3))
                                .foregroundColor(Color(hex: "eeeeee"))
                        }
                    }
                    .padding(.bottom, 3.3)
                }
            }
            
            Rectangle()
                .foregroundColor(Color(hex: "909090").opacity(0.5))
                .frame(width: screenSize().width - 26.7, height: 1)
        }
        .frame(width: screenSize().width - 26.7, height: 130, alignment: .center)
    }
}