//
//  LiveReservationStatusItemView.swift
//  SodaLive
//
//  Created by klaus on 2023/08/11.
//

import SwiftUI
import Kingfisher

struct LiveReservationStatusItemView: View {
    
    let item: GetLiveReservationResponse
    
    var body: some View {
        HStack(spacing: 0) {
            KFImage(URL(string: item.coverImageUrl))
                .cancelOnDisappear(true)
                .downsampling(
                    size: CGSize(
                        width: 80,
                        height: 116.7
                    )
                )
                .resizable()
                .scaledToFill()
                .frame(width: 80, height: 116.7, alignment: .top)
                .clipped()
                .cornerRadius(4.7)
            
            VStack(alignment: .leading, spacing: 0) {
                Text(item.beginDateTime)
                    .font(.custom(Font.medium.rawValue, size: 9.3))
                    .foregroundColor(Color(hex: "ffd300"))
                
                Text(item.masterNickname)
                    .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"))
                    .lineLimit(2)
                    .padding(.top, 4.3)
                
                HStack(spacing: 0) {
                    Text(
                        item.price > 0 ?
                        "\(item.price)캔" :
                            "무료"
                    )
                    .font(.custom(Font.medium.rawValue, size: 12))
                    .foregroundColor(Color(hex: "e2e2e2").opacity(0.4))
                    
                    Spacer()
                    
                    if !item.cancelable {
                        Text("예약 취소 불가")
                            .font(.custom(Font.light.rawValue, size: 10.7))
                            .foregroundColor(Color(hex: "777777"))
                    }
                }
                .padding(.top, 15.3)
            }
            .padding(.leading, 20)
            .padding(.trailing, 16.3)
            
            if item.cancelable {
                Spacer()
                
                Text("예약\n취소")
                    .font(.custom(Font.bold.rawValue, size: 12))
                    .foregroundColor(Color(hex: "9970ff"))
                    .padding(10.7)
                    .overlay(
                        RoundedRectangle(cornerRadius: 6.7)
                            .stroke(
                                Color(hex: "9970ff"),
                                lineWidth: 1
                            )
                    )
                    .onTapGesture {
                        AppState.shared.setAppStep(
                            step: .liveReservationCancel(reservationId: item.reservationId)
                        )
                    }
            }
        }
        .padding(13.3)
        .background(Color.black)
    }
}

struct LiveReservationStatusItemView_Previews: PreviewProvider {
    static var previews: some View {
        LiveReservationStatusItemView(
            item: GetLiveReservationResponse(
                reservationId: 0,
                roomId: 1,
                title: "여자들이 좋아하는 남자 스타일은??여자들이 좋아하는 남자 스타일은??여자들이 좋아하는 남자 스타일은??",
                coverImageUrl: "https://test-cf.sodalive.net/profile/default-profile.png",
                price: 0,
                masterNickname: "사냥꾼1004",
                beginDateTime: "2021.05.20 SUN 10p.m",
                cancelable: false
            )
        )
    }
}
