//
//  MessageNotificationView.swift
//  AlloVoisinsSwiftUI
//
//  Created by Victor on 29/01/2025.
//

import SwiftUI

struct AVMessageNotification: Codable {
    let displayName: String
    let message: String
    let avatarUrl: String
    let actionUrl: String
    let isNewUser: Bool
    let countUnreadMessage: Int

    enum CodingKeys: String, CodingKey {
        case displayName = "display_name"
        case message
        case avatarUrl = "avatar_url"
        case actionUrl = "action_url"
        case isNewUser = "is_new_user"
        case countUnreadMessage = "count_unread_message"
    }
}

struct MessageNotificationView: View {
    let notification: AVMessageNotification

    var body: some View {
        HStack(alignment: .center, spacing: 8) {
            AVAvatar(model: AVAvatarModel(avatarString: notification.avatarUrl, onlineStatus: .online(), sizing: .M))
                .frame(width: 48, height: 48)
            VStack(alignment: .leading) {
                SQText(notification.displayName)
                    .sqFont(.semiBold)
                SQText(notification.message)
                    .sqSize(14)
                    .sqColor(.sqNeutral(70))
                    .lineLimit(1)
            }
            Spacer()
            VStack {
                Circle()
                    .frame(width: 12, height: 12)
                    .foregroundStyle(Color.sqSemanticBlue)
                    .padding(.top, 8)
                Spacer()
            }
        }
        .padding(.horizontal, 16)
        .padding(.vertical, 12)
        .frame(height: 80)
        .background {
            RoundedRectangle(cornerRadius: 8)
                .fill(Color.white)
                .shadow(color: .black.opacity(0.15), radius: 8, x: 0, y: 4)
        }
    }
}

#Preview {
    MessageNotificationView(notification: AVMessageNotification(displayName: "Lucas E.", message: "Bonjour je voudrais une  super voiture pour déplacer des ", avatarUrl: "https://public-allo10.allovoisins.com//assets/default_avatars/100/Avatar0.png", actionUrl: "", isNewUser: true, countUnreadMessage: 1))
}
