//
//  MapTaskView.swift
//  forShip
//
//  Created by Mamoru Sugita on 2023/10/17.
//

import SwiftUI

enum TaskViewMode{
    case SwitchingMenu
    case EcaList
    case EcaSetting
    
    var title: String{
        switch self{
        case .SwitchingMenu:
            "Fuel Switching"
        case .EcaList:
            "ECA List"
        case .EcaSetting:
            ""
        }
    }
}


struct MapTaskView: View {
    @State var viewMode: TaskViewMode = .SwitchingMenu
    var body: some View {
        VStack{
            Capsule()
                .foregroundColor(Color(.systemGray5))
                .frame(width: 45, height: 3)
                .padding(.top, 10)

            //タイトルエリア
            HStack{
                
                Button(action: {
                    viewMode = .SwitchingMenu
                }, label: {
                    if viewMode != .SwitchingMenu{
                        Image("ink_02")
                    }
                })
                .frame(width: 48, height: 48)
                
                
                Spacer()
                
                Text(viewMode.title)
                    .frame(height: 20)
                    .padding(.vertical, 14)
                
                Spacer()
                
                
                Button(action: {
                    
                }, label: {
                    Image("closeIcon")
                })
                .frame(width: 48, height: 48)

                
                    
            }
            .padding(EdgeInsets(top: 10, leading: 8, bottom: 13, trailing: 17))
            
            
            Divider()
                .background(ColorSet.LineColor03.color)
            
            ScrollView(.vertical){
                switch viewMode {
                case .SwitchingMenu:
                    TaskSwitchingMenuView(viewMode: $viewMode)
                case .EcaList:
                    EcaListView()
                case .EcaSetting:
                    EcaSettingView()
                }
                
            }
            .padding(.leading, 20)
            .padding(.trailing, 10)
            
            Spacer()
                .frame(height: 100)
            
        }.onAppear{
            EcaCoordinatesTable().setEcaData()
        }
    }
}

#Preview {
    MapTaskView()
}
