Gitfed
bastien-mrq/bt-message / btmessage / Views / MessageBubble.swift
// MessageBubble.swift

import SwiftUI

struct MessageBubble: View {
    let message: ChatMessage

    var body: some View {
        HStack {
            if message.isLocal { Spacer() }

            VStack(alignment: message.isLocal ? .trailing : .leading, spacing: 2) {
                Text(message.text)
                    .padding(.horizontal, 12)
                    .padding(.vertical, 8)
                    .background(message.isLocal ? Color.blue : Color(.systemGray5))
                    .foregroundColor(message.isLocal ? .white : .primary)
                    .clipShape(RoundedRectangle(cornerRadius: 16))

                HStack(spacing: 4) {
                    Text(message.timestamp, style: .time)
                        .font(.caption2)
                        .foregroundColor(.secondary)
                    if message.isLocal {
                        Image(systemName: message.delivered ? "checkmark.circle.fill" : "clock")
                            .font(.caption2)
                            .foregroundColor(message.delivered ? .green : .secondary)
                    }
                }
            }
            .frame(maxWidth: 280, alignment: message.isLocal ? .trailing : .leading)

            if !message.isLocal { Spacer() }
        }
    }
}