//
//  CozyChatBubble.swift
//  lichunWebsocket
//
//  Cozy chat bubble with warm styling
//

import SwiftUI

struct CozyChatBubble: View {
    let text: String
    let timestamp: String
    let isPlayer: Bool

    var body: some View {
        HStack(alignment: .bottom, spacing: AppSpacing.sm) {
            if isPlayer {
                Spacer(minLength: 60)
            }

            VStack(alignment: isPlayer ? .trailing : .leading, spacing: AppSpacing.xs) {
                // Message bubble
                Text(text)
                    .font(.appBody)
                    .foregroundColor(isPlayer ? .white : AppColors.primaryText)
                    .padding(.horizontal, 16)
                    .padding(.vertical, 12)
                    .background(
                        Group {
                            if isPlayer {
                                LinearGradient(
                                    colors: [
                                        AppColors.primary,
                                        AppColors.primary.darker(by: 0.08)
                                    ],
                                    startPoint: .topLeading,
                                    endPoint: .bottomTrailing
                                )
                            } else {
                                Color(hex: 0xF5EDE6)
                            }
                        }
                    )
                    .cornerRadius(20)
                    .shadow(
                        color: isPlayer
                            ? AppColors.primary.opacity(0.4)
                            : Color.black.opacity(0.06),
                        radius: 6,
                        x: 0,
                        y: 3
                    )
                    .shadow(
                        color: isPlayer
                            ? AppColors.primary.opacity(0.2)
                            : Color.black.opacity(0.03),
                        radius: 3,
                        x: 0,
                        y: 1
                    )

                // Timestamp
                Text(timestamp)
                    .font(.system(size: 10, weight: .medium, design: .rounded))
                    .foregroundColor(AppColors.secondaryText)
                    .padding(.horizontal, AppSpacing.xs)
            }

            if !isPlayer {
                Spacer(minLength: 60)
            }
        }
    }
}

// MARK: - Preview
#if DEBUG
struct CozyChatBubble_Previews: PreviewProvider {
    static var previews: some View {
        VStack(spacing: 16) {
            CozyChatBubble(
                text: "Hey! How are you doing today?",
                timestamp: "10:30 AM",
                isPlayer: false
            )

            CozyChatBubble(
                text: "I'm doing great, thanks for asking!",
                timestamp: "10:31 AM",
                isPlayer: true
            )
        }
        .padding()
        .background(AppColors.background)
    }
}
#endif
