import SwiftUI

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

    var body: some View {
        HStack{
            Button(action: {
                taskViewModel.viewMode = .FuelSwitching
            }, label: {
                Image("ink_02")
            })
            .frame(width: 48, height: 48)

            Spacer()

            Text(TaskViewMode.EcaList.title)
                .font(FontStyle.TitleL.font)
                .frame(height: 20)
                .padding(.vertical, 14)

            Spacer()

            Button(action: {
            }, label: {
            })
            .frame(width: 48, height: 48)
        }
        .padding(EdgeInsets(top: 10, leading: 8, bottom: 13, trailing: 17))

        Divider()
            .background(ColorSet.LineColor03.color)

        ScrollViewReader { proxy in
            ScrollView(.vertical){
                EcaListView(taskViewModel: taskViewModel)
            }
            .onChange(of: taskViewModel.viewMode){ newViewMode in
                proxy.scrollTo(0, anchor: .top)
            }
        }

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

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