//
//  MenuManualRADARView.swift
//  Sailassist
//
//  Created by 三浦薫巳 on 2023/12/14.
//

import SwiftUI
import PDFKit

struct MenuManualRADARView: View {
    @State var isAlert: Bool = false
    @Binding var path : [MenuPath]
    var body: some View {
        VStack{
            MenuTitleView(path: $path, title: MenuPath.ManualRADAR.title)

            Button{
                if Preferences.RADARBasicUrl != nil{
                    path.append(.ManualRADARBasic)
                }else{
                    if let url = PDFDownloadManager.main.downloadFile(urlString: "https://samsdbg.jmarinesafety.jp/gps_editor/gps_help.pdf", fileName: "ECDIS.pdf"){
                        Preferences.ECDISBasicUrl = url
                        path.append(.ManualRADARBasic)
                    }else{
                        isAlert = true
                    }
                }
            }label: {
                MenuContentView(content: .ManualRADARBasic)
            }

            Button{
                if Preferences.RADARFunctionUrl != nil{
                    path.append(.ManualRADARFunction)
                }else{
                    if let url = PDFDownloadManager.main.downloadFile(urlString: "https://samsdbg.jmarinesafety.jp/gps_editor/gps_help.pdf", fileName: "ECDIS.pdf"){
                        Preferences.RADARFunctionUrl = url
                        path.append(.ManualRADARFunction)
                    }else{
                        isAlert = true
                    }
                }
            }label: {
                MenuContentView(content: .ManualRADARFunction)
            }

            Spacer()
        }
        .background(ColorSet.BackgroundPrimary.color)
        .alert("delete", isPresented: $isAlert) {
            Button(role: .destructive) {

            } label: {
                Text("delete")
            }

        } message: {
            Text("eca delete")
        }
    }
}

#Preview {
    MenuManualRADARView(path: .constant([.ManualRADAR]))
}
