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

import SwiftUI
import PDFKit

struct MenuManualRADARView: 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.ManualRADAR.title)

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

                if let manual = SharingData.my.manualUrls.filter({$0.identifer!.contains(MenuPath.ManualRADARFunction.fileIdntifer!)}).first{
                    ManualDownloadButton(manualType: .ManualRADARFunction, downloadUrl: manual.path,version: Preferences.RADARFunctionManualVer, newVersion: manual.name, isAlert: $isAlert, isLoadingView: $isLoadingView){
                        path.append(.ManualRADARFunction)
                        Preferences.RADARFunctionManualVer = manual.name
                    }
                }
            } else {
                Text("Now Loading...").padding()
                ProgressView()
            }
            Spacer()
        }
        .background(ColorSet.BackgroundPrimary.color)
        .alert("Error", isPresented: $isAlert) {
            Button("OK") {}
        } message: {
            Text("Network Error")
        }
    }
}

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