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

import SwiftUI

struct EcaListView: View {
    @ObservedObject var ecaData = SharingData.eca
    
    var body: some View {
        ForEach(ecaData.ecaArea.map{ $0.1 }, id: \.name){ eca in
            HStack {
                Text(eca.name)
                    .font(FontStyle.DefaultText.font)
                    .foregroundColor(ColorSet.Body.color)
                    .onTapGesture {
                        ecaData.foucusEca = eca.name
                    }
                Spacer()
                if !eca.isEnable{
                    Button(action: {
                        var newData = eca
                        newData.isEnable.toggle()
                        ecaData.editEcaArea(key: eca.name, value: newData)
                    }, label: {
                        Image("icon_plus")
                            .resizable()
                            .frame(width: 12, height: 12)
                            .padding(8)
                    })
                    .frame(width: 28, height: 28)
                    .background(.primaryActiveIcon)
                    .cornerRadius(50)
                    .padding()
                }else{
                    Text("Registerd")
                        .font(FontStyle.SupplementText2.font)
                        .frame(height: 25)
                        .foregroundColor(ColorSet.ButtonDisable.color)
                        .padding(.vertical, 4)
                        .padding(.horizontal, 10)
                        .background(ColorSet.PrimaryDisable.color)
                        .cornerRadius(99)
                }
                
            }
            .frame(height: 62)
            .padding(.horizontal, 30)
            
            Divider()
                .background(.white)
        }
    }
}

#Preview {
    EcaListView()
}

