//
//  LiveReservationItemView.swift
//  SodaLive
//
//  Created by klaus on 2023/08/10.
//

import SwiftUI
import Kingfisher

struct LiveReservationItemView: View {
    
    let item: GetRoomListResponse
    
    var body: some View {
        VStack(alignment: .leading, spacing: 13.3) {
            HStack(spacing: 20) {
                ZStack(alignment: .topLeading) {
                    KFImage(URL(string: item.coverImageUrl))
                        .cancelOnDisappear(true)
                        .downsampling(
                            size: CGSize(
                                width: 80,
                                height: 116
                            )
                        )
                        .resizable()
                        .scaledToFill()
                        .frame(width: 80, height: 116, alignment: .top)
                        .cornerRadius(4.7)
                        .clipped()
                }
                
                HStack(alignment: .top, spacing: 0) {
                    VStack(alignment: .leading, spacing: 0) {
                        Text(item.beginDateTime)
                            .font(.custom(Font.medium.rawValue, size: 9.3))
                            .foregroundColor(Color(hex: "ffd300"))
                        
                        Text(item.creatorNickname)
                            .font(.custom(Font.medium.rawValue, size: 11.3))
                            .foregroundColor(Color(hex: "bbbbbb"))
                            .padding(.top, 10)
                        
                        Text(item.title)
                            .font(.custom(Font.medium.rawValue, size: 15.3))
                            .foregroundColor(Color(hex: "e2e2e2"))
                            .padding(.top, 4.3)
                        
                        Spacer()
                        
                        if item.isReservation {
                            Text("예약완료")
                                .font(.custom(Font.medium.rawValue, size: 11.3))
                                .foregroundColor(Color(hex: "d2d2d2"))
                                .padding(.horizontal, 7)
                                .padding(.vertical, 4)
                                .background(Color(hex: "533d89"))
                                .cornerRadius(10)
                        } else {
                            if item.price > 0 {
                                Text("\(item.price)캔")
                                    .font(.custom(Font.medium.rawValue, size: 12))
                                    .foregroundColor(
                                        Color(hex: "e2e2e2")
                                            .opacity(0.5)
                                    )
                                
                            } else {
                                Text("무료")
                                    .font(.custom(Font.medium.rawValue, size: 12))
                                    .foregroundColor(
                                        Color(hex: "e2e2e2")
                                            .opacity(0.5)
                                    )
                            }
                        }
                    }
                    
                    Spacer()
                    
                    if item.isPrivateRoom {
                        Image("ic_lock")
                            .resizable()
                            .frame(width: 20, height: 20)
                    }
                }
                .padding(.vertical, 6.7)
            }
            
            Divider()
                .frame(height: 1)
                .background(Color(hex: "909090").opacity(0.5))
        }
        .frame(width: screenSize().width - 26.7, height: 130, alignment: .center)
    }
}

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