import SwiftUI

struct EcaSettingMainView: View {
    @ObservedObject var taskViewModel = TaskViewModel()

    var body: some View {
        TaskTitleView(
            taskViewModel: taskViewModel,
            title: TaskViewMode.EcaSetting.title,
            viewMode: TaskViewMode.FuelSwitching
        )

        ScrollViewReader { proxy in
            ScrollView(.vertical){
                if let edittingEcaArea = taskViewModel.edittingEcaArea {
                    EcaSettingView(taskViewModel: taskViewModel, edittingEca: edittingEcaArea)
                }
            }
            .onChange(of: taskViewModel.viewMode){ newViewMode in
                proxy.scrollTo(0, anchor: .top)
            }
        }

        Spacer()
            .frame(height: 55)
    }
}

#Preview {
    EcaSettingMainView(taskViewModel: TaskViewModel())
}
