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

import SwiftUI
import PDFKit

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

            if !isLoadingView {
                if let manual = SharingData.my.manualUrls.filter({$0.identifer == MenuPath.ManualECDISBasic.fileIdntifer}).first{
                    ManualDownloadButton(manualType: .ManualECDISBasic, downloadUrl: manual.path,version: Preferences.ECDISBasicManualVer, newVersion: manual.name, isAlert: $isAlert, isLoadingView: $isLoadingView){
                        path.append(.ManualECDISBasic)
                        Preferences.ECDISBasicManualVer = manual.name
                    }
                }

                if let manual = SharingData.my.manualUrls.filter({$0.identifer == MenuPath.ManualECDISFunction.fileIdntifer}).first{
                    ManualDownloadButton(manualType: .ManualECDISFunction, downloadUrl: manual.path,version: Preferences.ECDISFunctionManualVer, newVersion: manual.name, isAlert: $isAlert, isLoadingView: $isLoadingView){
                        path.append(.ManualECDISFunction)
                        Preferences.ECDISFunctionManualVer = manual.name
                    }
                }
            } else {
                Text("Now Loading...").padding()
                ProgressView()
            }
            Spacer()
        }
        .background(ColorSet.BackgroundPrimary.color)
        .alert("delete", isPresented: $isAlert) {
            Button(role: .destructive) {

            } label: {
                Text("delete")
            }

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

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