//
//  MapInformation.swift
//  Sailassist
//
//  Created by 三浦薫巳 on 2024/06/12.
//

import SwiftUI

struct MapInformation: View {
    @ObservedObject var ship = SharingData.location
    @ObservedObject var ngaData = SharingData.nga

    var body: some View {
        VStack {
            VStack {
                Text(presentLocation())
                    .font(Font(UIFont.monospacedSystemFont(ofSize: 12, weight: .regular)))
                    .foregroundColor(Color.black)
                    .padding(5)
                    .background(Color.white.opacity(0.7))
                    .cornerRadius(3)
            }
            .padding(.top, 100)
            .padding(.trailing, positionLocation())
            VStack {
                ForEach(ngaData.ngaArea.map{ $0.1 }.filter{ $0.passingCnt > 0 }, id: \.name) { nga in
                    Text("Entering NGA \(nga.name)")
                        .font(FontStyle.EmphasisText.font)
                        .foregroundColor(Color.white)
                        .padding(5)
                        .background(Color.red.opacity(0.7))
                        .cornerRadius(3)
                }
            }
            Spacer()
        }
    }

    func presentLocation() -> String {
        var location = " 00°00.000'N\n000°00.000'E"
        if let shipPos = ship.location {
            location = LocationCalculation.locationDegtoString(location: shipPos)
        }
        return location
    }

    func positionLocation() -> CGFloat {
        var yPos: CGFloat = 200
        if UIDevice.current.userInterfaceIdiom == .pad {
            yPos = 900
        }

        return yPos
    }
}

#Preview {
    MapInformation()
}

