//
//  NotificationContentView.swift
//  Sailassist
//
//  Created by Mamoru Sugita on 2023/11/27.
//
import SwiftUI
import CoreLocation

struct NotificationContentView: View {
    @EnvironmentObject var selectedTabModel: SelectedTabModel

    var pushData: ResPushHistory
    var body: some View {
        VStack(alignment: .leading, spacing: 4){
            HStack(spacing: 10) {
                Text(pushData.time ?? "2023-07-13T08::17:40Z")
                    .foregroundColor(ColorSet.BodyDescriptiion.color)
                    .font(FontStyle.SupplementText2.font)
                
                Text(PushStatus(rawValue: pushData.status ?? 0)?.title ?? PushStatus.Unknown.title)
                    .padding(EdgeInsets(top: 4, leading: 8, bottom: 4, trailing: 8))
                    .border(ColorSet.Body.color, width: 1, cornerRadius: 4)
                    .foregroundColor(ColorSet.Body.color)
                    .font(FontStyle.SupplementText2.font)
                
                Spacer()
            }
            HStack(spacing: 10) {
                Text(pushData.title ?? "JTest-Ship")
                    .foregroundColor(ColorSet.Body.color)
                    .font(FontStyle.EmphasisText.font)

                Spacer()

                if let position = pushData.position {
                    if position.lat != nil && position.lon != nil {
                        Image("map_pin")
                            .resizable()
                            .frame(width: 20, height: 20)
                    }
                }
            }

            Text(pushData.message ?? "Fire emergency notice from ship")
                .foregroundColor(ColorSet.BodyDescriptiion.color)
                .font(FontStyle.SupplementText2.font)
        }
        .padding(EdgeInsets(top: 17, leading: 30, bottom: 17, trailing: 30))
        .onAppear {
            SharingData.pushHistory.viewCnt = 0
        }
    }
}

#Preview {
    NotificationContentView(pushData: ResPushHistory())
}
