//
//  CountdownFormView.swift
//  LeCountdown
//
//  Created by Laurent Morvillier on 27/01/2023.
//

import SwiftUI


struct CountdownFormView : View {
    
    var secondsBinding: Binding<String>
    var minutesBinding: Binding<String>
    var nameBinding: Binding<String>

    var imageBinding: Binding<CoolPic>
    var soundBinding: Binding<Sound>
    var repeatsBinding: Binding<Bool>

    var textFieldIsFocused: FocusState<Bool>.Binding

    var body: some View {
        Form {
            Section(header: Text("Duration")) {
                TextField("minutes", text: minutesBinding)
                    .keyboardType(.numberPad)
                    .focused(textFieldIsFocused)
                TextField("seconds", text: secondsBinding)
                    .keyboardType(.numberPad)
                    .focused(textFieldIsFocused)
            }
            Section(header: Text("Name for tracking the activity")) {
                TextField("name", text: nameBinding)
                    .focused(textFieldIsFocused)
            }

            SoundImageFormView(imageBinding: imageBinding,
                               soundBinding: soundBinding,
                               repeatsBinding: repeatsBinding)
        }
        
    }
    
}

struct CountdownFormView_Previews: PreviewProvider {
    
    @FocusState static var textFieldIsFocused: Bool
    
    static var previews: some View {
        CountdownFormView(secondsBinding: .constant(""), minutesBinding: .constant(""),
                          nameBinding: .constant(""), imageBinding: .constant(.pic3), soundBinding: .constant(.trainhorn), repeatsBinding: .constant(true), textFieldIsFocused: $textFieldIsFocused)
    }
}
