//
//  EcaListView.swift
//  forShip
//
//  Created by Mamoru Sugita on 2023/10/18.
//

import SwiftUI

struct EcaListView: View {
    @ObservedObject var sharingData = SharingData.shared
    
    var body: some View {
        ForEach(sharingData.ecaArea.map{ $0.1 }, id: \.name){ eca in
            HStack {
                Text(eca.name)
                    .padding(17)
                Spacer()
                if !eca.isEnable{
                    Button(action: {
                        var newData = eca
                        newData.isEnable.toggle()
                        sharingData.editEcaArea(key: eca.name, value: newData)
                    }, label: {
                        Image("icon_plus")
                            .padding()
                    })
                    .background(.primaryActiveIcon)
                    .cornerRadius(50)
                    .padding()
                }else{
                    Text("Registerd")
                        .frame(height: 24)
                        .background(.primaryDisable)
                        .cornerRadius(12)
                        .padding()
                }
                
            }
            
            Divider()
        }
    }
}

#Preview {
    EcaListView()
        .environmentObject(SharingData.shared)
}

