//
//  MenuGpsSelectView.swift
//  Sailassist
//
//  Created by Mamoru Sugita on 2023/11/21.
//

import SwiftUI

struct MenuGpsSelectView: View {
    @Binding var path : [MenuPath]
    @State var selected : GpsSelect = .Mobile
    
    enum GpsSelect: String, CaseIterable{
        case Mobile
        case Cloud
        
        var title: String{
            switch self {
            case .Mobile:
                "Mobile Phone GPS"
            case .Cloud:
                "Cloud GPS"
            }
        }
    }
    
    var body: some View {
        VStack{
            MenuTitleView(path: $path, title: MenuPath.Setting.title)
            
            ForEach(GpsSelect.allCases, id:\.rawValue){ content in
                SelectContentView(selected: $selected, content: content)
            }
            Spacer()
        }
        .background(ColorSet.BackgroundPrimary.color)
    }
    
    struct SelectContentView: View {
        @Binding var selected : GpsSelect
        var content : GpsSelect
        var body: some View {
            VStack(spacing: 0){
                Button{
                    selected = content
                    if content == .Mobile {
                        Preferences.LocationType = 0
                    } else {
                        Preferences.LocationType = 1
                    }
                    SharingData.my.setLocation()
                }label:{
                    HStack {
                        Text(content.title)
                            .font(FontStyle.EmphasisText.font)
                            .foregroundColor(ColorSet.Body.color)
                        
                        Spacer()
                        
                        if selected == content{
                            Image(systemName: "checkmark.square.fill")
                                .resizable()
                                .frame(width: 22, height: 22)
                        }else{
                            Image(systemName: "square")
                                .resizable()
                                .frame(width: 22, height: 22)
                        }
                    }
                    .padding(.vertical, 17)
                    .padding(.horizontal, 30)
                }
                Divider()
                    .background(ColorSet.LineColor04.color)
            }
        }
    }
    
}

#Preview {
    MenuGpsSelectView(path: .constant([.Setting]))
}
