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

import SwiftUI

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


struct MapTaskView: View {
    @State var viewMode: TaskViewMode = .SwitchingMenu
    @State var edittingEcaArea: RegisteredEca? = nil
    @State var isShowSettingView : Bool = false
    var body: some View {
        VStack{
            Capsule()
                .foregroundColor(ColorSet.ScrollBarColor.color)
                .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)
                    .font(FontStyle.TitleL.font)
                    .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:
                    if let edittingEcaArea = edittingEcaArea, isShowSettingView{
                        EcaSettingView(isShowSettingEca: $isShowSettingView, edittingEca: edittingEcaArea)
                    }else{
                        TaskSwitchingMenuView(viewMode: $viewMode, edittingEcaArea: $edittingEcaArea, isShowSettingEca: $isShowSettingView)
                    }
                case .EcaList:
                    EcaListView()
                }
                
            }
            
            Spacer()
                .frame(height: 55)
            
        }.onAppear{
            EcaCoordinatesTable().setEcaData()
        }
    }
}

#Preview {
    MapTaskView()
}
