//
//  MyChatContentView.swift
//  Sailassist
//
//  Created by Mamoru Sugita on 2023/11/08.
//

import SwiftUI

struct MyChatContentView: View {
    var message : ChatMessage
    var body: some View {
        HStack {
            Spacer()
            VStack(alignment: .trailing, spacing: 6) {
                Text(message.message)
                    .font(FontStyle.DefaultText.font)
                    .foregroundColor(ColorSet.BodyChat.color)
                    .padding(15)
                    .background(ColorSet.ChatBaloon.color)
                    .cornerRadius(10, corners: [.tl, .tr, .bl])
                
                HStack(spacing: 0){
                    Text(DateTextLib.ISO86012FormatText(message.time, format: "yyyy/MM/dd hh:mm", errFormat: ""))
                        .padding(.trailing, 8)
                    
                    Image(systemName: "eye.fill")
                        .resizable()
                        .scaledToFit()
                        .frame(width: 17, height: 17)
                        .padding(.trailing, 4)
                    
                    Text(String(message.viewer.count))
                }
                .font(FontStyle.DateText.font)
                .foregroundColor(ColorSet.BodyDescriptiion.color)
            }
            .padding(.trailing, 20)
        }
        .padding(.leading, 80)
    }
}

#Preview {
    MyChatContentView(message: ChatMessage(
        shipId: 10000003,
        messageId: "92c2dfb5-f5ed-4943-98a3-9848d7f9a962",
        type: 0,
        time: "2023-10-06T01:51:01.872Z",
        location: 1,
        from: "はだだ",
        fromId: "487420489",
        message: "999",
        stampId: 0,
        viewer: [
            Viewer(
                time: "2023-10-06T01:51:12.973Z",
                location: 1,
                id: ""),
            Viewer(
                time: "2023-10-06T01:51:12.973Z",
                location: 2,
                id: "")
        ]
    ))
}
