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

import SwiftUI
import PDFKit

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

            Button{
                if Preferences.ECDISBasicUrl != nil{
                    path.append(.ManualECDISBasic)
                }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(.ManualECDISBasic)
                    }else{
                        isAlert = true
                    }
                }
            }label: {
                MenuContentView(content: .ManualECDISBasic)
            }

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

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

            } label: {
                Text("delete")
            }

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

#Preview {
    MenuManualECDISView(path: .constant([.ManualECDIS]))
}
