//
//  MenuView.swift
//  forShip
//
//  Created by Mamoru Sugita on 2023/10/16.
//

import SwiftUI
import PDFKit

enum MenuPath: String, Hashable{
    case Manual
    case ManualECDIS
    case ManualRADAR
    case ManualJmarineNeCST
    case Information
    case Help
    case AboutApp
    case ContactUs
    
    var title: String{
        switch self {
        case .Manual:
            "Equipment manual"
        case .ManualECDIS:
            "ECDIS"
        case .ManualRADAR:
            "RADAR"
        case .ManualJmarineNeCST:
            "J-marine NeCST"
        case .Information:
            "Information"
        case .Help:
            "Help"
        case .AboutApp:
            "About this App"
        case .ContactUs:
            "Contact Us"
        }
    }
}

struct MenuView: View {
    @State var path: [MenuPath] = []
    
    var body: some View {
        NavigationStack(path: $path){
            VStack(spacing: 0) {
                MenuTitleView(path: $path)
                
                HStack {
                    VStack(alignment: .leading, spacing: 10){
                        Text("Japan Radio Co.,Ltd.")
                            .font(FontStyle.TitleL.font)
                            .foregroundColor(ColorSet.Body.color)
                        Text("会社名一般")
                            .font(FontStyle.EmphasisText.font)
                            .foregroundColor(ColorSet.BodyDescriptiion.color)
                    }
                    .padding(.horizontal, 30)
                    .padding(.vertical, 17)
                    Spacer()
                }
                
                Divider()
                    .background(ColorSet.LineColor04.color)
                
                Button{
                    path.append(.Manual)
                }label: {
                    MenuContentView(content: .Manual)

                }
                
                Button{
                    path.append(.Information)
                }label: {
                    MenuContentView(content: .Information)
                }
                
                Button{
                    path.append(.Help)
                }label: {
                    MenuContentView(content: .Help)
                }
                
                Button{
                    path.append(.AboutApp)
                }label: {
                    MenuContentView(content: .AboutApp)
                }
                
                Button{
                    path.append(.ContactUs)
                }label: {
                    MenuContentView(content: .ContactUs)
                }
                
                Spacer()
            }
            .background(ColorSet.BackgroundPrimary.color)
            .navigationTitle("")
            .navigationBarHidden(true)
            .navigationDestination(for: MenuPath.self) { goto in
                if goto == .Manual{
                    MenuManualView(path: $path)
                        .navigationBarHidden(true)
                }else{
                    VStack(spacing: 0) {
                        MenuTitleView(path: $path, title: goto.title)
                        
                        if let url = Preferences.ECDISUrl{
                            PDFViewer(url: url)
                        }else{
                            Spacer()
                        }
                    }
                        .navigationBarHidden(true)
                        .background(ColorSet.BackgroundPrimary.color)

                }
            }
        }
    }
}

#Preview {
    MenuView()
}
