//
//  LiveRoomDonationMessageItemView.swift
//  SodaLive
//
//  Created by klaus on 5/11/24.
//

import SwiftUI

struct LiveRoomDonationMessageItemView: View {
    
    let message: LiveRoomDonationMessage
    let creatorId: Int
    let deleteDonationMessage: (String) -> Void
    
    var body: some View {
        HStack(alignment: .top, spacing: 0) {
            VStack(alignment: .leading, spacing: 8) {
                Text("\(message.nickname)님이")
                    .font(.custom(Font.medium.rawValue, size: 13.3))
                    .foregroundColor(.white)
                
                if !message.canMessage.trimmingCharacters(in: .whitespaces).isEmpty {
                    Text("\(message.canMessage)")
                        .font(.custom(Font.medium.rawValue, size: 13.3))
                        .foregroundColor(.white)
                }
                
                Text("'\(message.donationMessage)'")
                    .font(.custom(Font.medium.rawValue, size: 13.3))
                    .foregroundColor(.white)
            }
            
            Spacer()
            
            if creatorId == UserDefaults.int(forKey: .userId) {
                Image("ic_close_white")
                    .resizable()
                    .frame(width: 13.3, height: 13.3)
                    .onTapGesture { deleteDonationMessage(message.uuid) }
            }
        }
        .padding(13.3)
        .background(message.canMessage.trimmingCharacters(in: .whitespaces).isEmpty ? Color(hex: "c25264").opacity(0.8) : Color.gray33)
        .cornerRadius(5.3)
    }
}

#Preview("일반후원 메시지") {
    LiveRoomDonationMessageItemView(
        message: LiveRoomDonationMessage(
            uuid: "",
            nickname: "유저2님이",
            canMessage: "10캔을 후원하셨습니다",
            donationMessage: "ㅅㅅㅅ"
        ),
        creatorId: 0,
        deleteDonationMessage: { _ in }
    )
}

#Preview("룰렛후원 메시지") {
    LiveRoomDonationMessageItemView(
        message: LiveRoomDonationMessage(
            uuid: "",
            nickname: "유저2님의 룰렛 결과?",
            canMessage: "",
            donationMessage: "[테스트] 당첨!"
        ),
        creatorId: 0,
        deleteDonationMessage: { _ in }
    )
}
