import SwiftUI

struct NgaSettingMainView: View {
    @ObservedObject var taskViewModel = TaskViewModel()
    @ObservedObject var nga = SharingData.nga
    @ObservedObject var map = SharingData.map

    var body: some View {
        //タイトルエリア
        HStack{
            Button(action: {
                if taskViewModel.viewMode == .NgaSetting && nga.editType == EditNgaType.movePoint {
                    nga.editNga = nga.moveNga
                    nga.editType = EditNgaType.addPoint
                    map.isMapFree = true
                } else {
                    taskViewModel.viewMode = .NgaNotification
                    nga.editType = EditNgaType.registered
                }
            }, label: {
                Image("ink_02")
            })
            .frame(width: 48, height: 48)

            Spacer()
            HStack(spacing: 0) {
                Text(TaskViewMode.NgaSetting.title)
                    .font(FontStyle.TitleL.font)
                    .foregroundColor(ColorSet.Body.color)
            }

            Spacer()

            Button(action: {
            }, label: {
            })
            .frame(width: 48, height: 48)
        }
        .frame(height: LayoutConstants.menuTitleHeight)

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

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

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

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