import SwiftUI

struct NgaMenuView: View {
    @ObservedObject var taskViewModel: TaskViewModel
    @ObservedObject var ngaData = SharingData.nga
    @Environment(\ .colorScheme) var colorScheme
    @State var isDelete: Bool = false
    var nga: RegisteredNga

    var body: some View {
        Menu {
            Text(nga.name)

            Button{
                ngaData.editNga = nga
                taskViewModel.viewMode = .NgaSetting
                ngaData.editType = EditNgaType.nonEdit
            } label: {
                Text("Edit NGA Setting")
            }

            //削除
            Button{
                ngaData.editNga = nga
                isDelete = true
            } label: {
                Text("Delete NGA Task")
            }.disabled(nga.isLock)
        } label: {
            Image(systemName: "ellipsis")
                .frame(width: 22, height: 22)
                .opacity(nga.isRunning ? 0.2 : 1.0)
                .foregroundColor(colorScheme == .light ? .black : .white)
        }
        .disabled(nga.isRunning)
        .alert("Delete", isPresented: $isDelete) {
            Button("Yes") {
                if let newData = ngaData.editNga {
                    ngaData.editNgaArea(value: newData, type: NgaOperation.Delete)
                }
            }
            Button("No"){}
        } message: {
            if let editNga = ngaData.editNga {
                Text("Delete " + editNga.name + " ?")
            }
        }
    }
}
