//
//  MenuManualView.swift
//  Sailassist
//
//  Created by Mamoru Sugita on 2023/11/10.
//

import SwiftUI
import PDFKit

struct MenuManualView: View {
    @State var isAlert: Bool = false
    @Binding var path : [MenuPath]
    var body: some View {
        VStack{
            MenuTitleView(path: $path, title: MenuPath.Manual.title)
            
            Button{
                if Preferences.ECDISUrl != nil{
                    path.append(.ManualECDIS)
                }else{
                    if let url =  PDFDownloadManager.main.downloadFile(urlString: "https://samsdbg.jmarinesafety.jp/gps_editor/gps_help.pdf", fileName: "ECDIS.pdf"){
                        Preferences.ECDISUrl = url
                        path.append(.ManualECDIS)
                    }else{
                        isAlert = true
                    }
                }
            }label: {
                MenuContentView(content: .ManualECDIS)
            }
            
            Button{
                path.append(.ManualRADAR)
            }label: {
                MenuContentView(content: .ManualRADAR)
            }
            
            Button{
                path.append(.ManualJmarineNeCST)
            }label: {
                MenuContentView(content: .ManualJmarineNeCST)
            }
            
            Spacer()
        }
        .background(ColorSet.BackgroundPrimary.color)
        .alert("delete", isPresented: $isAlert) {
            Button(role: .destructive) {
               
            } label: {
                Text("delete")
            }

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

#Preview {
    MenuManualView(path: .constant([.Manual]))
}
