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

import SwiftUI
import Kingfisher

struct LiveNowItemView: View {
    
    let item: GetRoomListResponse
    
    let width: CGFloat = 133.3
    let height: CGFloat = 176.7
    
    var body: some View {
        ZStack {
            KFImage(URL(string: item.coverImageUrl))
                .resizable()
                .scaledToFill()
                .frame(width: width, height: height, alignment: .top)
                .cornerRadius(4.7)
                .clipped()
            
            LinearGradient(
                colors: [Color.black.opacity(0.1), Color.black.opacity(0.8)],
                startPoint: .top,
                endPoint: .bottom
            )
            
            VStack(spacing: 0) {
                HStack(spacing: 3.3) {
                    Text(item.price > 0 ? "유료" : "무료")
                        .font(.custom(Font.medium.rawValue, size: 12))
                        .foregroundColor(Color.white)
                        .padding(.horizontal, 7.3)
                        .padding(.vertical, 4)
                        .background(Color(hex: item.price > 0 ? "881609" : "643bc8"))
                        .cornerRadius(10)
                    
                    Spacer()
                    
                    if item.isPrivateRoom {
                        Image("ic_lock")
                            .resizable()
                            .frame(width: 20, height: 20)
                    }
                }
                .padding(.horizontal, 3.3)
                .padding(.top, 3.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(Color.white)
                        .padding(.leading, 2.7)
                    
                    Spacer()
                    
                    Text("\(item.creatorNickname)")
                        .font(.custom(Font.medium.rawValue, size: 13.3))
                        .foregroundColor(Color.white)
                }
                .padding(.horizontal, 6.7)
                .padding(.bottom, 6.7)
            }
        }
        .frame(width: width, height: height)
    }
}

struct LiveNowItemView_Previews: PreviewProvider {
    static var previews: some View {
        LiveNowItemView(
            item: GetRoomListResponse(
                roomId: 99,
                title: "test",
                content: "testtest",
                beginDateTime: "2022.05.23 Mon 03:00 PM",
                numberOfParticipate: 3,
                numberOfPeople: 5,
                coverImageUrl: "https://test-cf.sodalive.net/profile/default-profile.png",
                isAdult: true,
                price: 0,
                tags: ["팬미팅", "힐링"],
                channelName: nil,
                creatorNickname: "user8",
                creatorId: 19,
                isReservation: false,
                isPrivateRoom: true
            )
        )
    }
}