<commit_before>import SwiftUI


struct EditView: View {
    @ObservedObject var countdown: Countdown
    
    var body: some View {
        Form {
            Section {
                if countdown.isScheduled {
                    DatePicker("", selection: $countdown.date)
                        .datePickerStyle(GraphicalDatePickerStyle())
                } else {
                    LengthPicker(countdown: countdown)
                        .foregroundColor(.primary)
                }
            }
            
            Section {
                Toggle("Show Early Warning", isOn: $countdown.showsEarlyWarning)
                    .foregroundColor(.primary)
                if countdown.showsEarlyWarning {
                    Picker(selection: $countdown.earlyWarningTime, label: Text("Trigger Time").foregroundColor(.primary)) {
                        ForEach([10, 9, 8, 7, 6, 5, 4, 3, 2], id: \.self) { minute in
                            Text("\(minute):00").tag(Double(minute * 60))
                        }
                    }
                }
            }
            
            Section {
                Toggle("Show Final Warning", isOn: $countdown.showsFinalWarning)
                    .foregroundColor(.primary)
                if countdown.showsFinalWarning {
                    Picker(selection: $countdown.finalWarningTime, label: Text("Trigger Time").foregroundColor(.primary)) {
                        ForEach([5, 4, 3, 2, 1, 0], id: \.self) { minute in
                            Text("\(minute):00").tag(Double(minute * 60))
                        }
                    }
                    Toggle("Flash at 0:00", isOn: $countdown.finalWarningFlashes)
                        .foregroundColor(.primary)
                }
            }
        }
        .navigationBarTitle("Edit Timer", displayMode: .inline)
    }
}


struct LengthPicker: View {
    @ObservedObject var countdown: Countdown
    
    #warning("Using strings until number formatter updates without hitting return")
    @State private var minutesString = "5"
    @State private var secondsString = "0"
    
    var body: some View {
        HStack {
            Spacer()
            Text("Minutes:")
            TextField("", text: $minutesString)
                .keyboardType(.numbersAndPunctuation)
                .textFieldStyle(RoundedBorderTextFieldStyle())
                .frame(width: 50)
                .onChange(of: minutesString) { value in
                    if let minutes = Int(value), minutes >= 0 {
                        countdown.length.minutes = minutes
                    } else if value != "" {
                        reloadStrings()
                    }
                }
            Text("Seconds:")
                .padding(.leading)
            TextField("", text: $secondsString)
                .keyboardType(.numbersAndPunctuation)<commit_msg>Add Done button back to EditView.<commit_after>import SwiftUI


struct EditView: View {
    @ObservedObject var countdown: Countdown
    @Environment(\.presentationMode) var presentationMode
    
    var body: some View {
        Form {
            Section {
                if countdown.isScheduled {
                    DatePicker("", selection: $countdown.date)
                        .datePickerStyle(GraphicalDatePickerStyle())
                } else {
                    LengthPicker(countdown: countdown)
                        .foregroundColor(.primary)
                }
            }
            
            Section {
                Toggle("Show Early Warning", isOn: $countdown.showsEarlyWarning)
                    .foregroundColor(.primary)
                if countdown.showsEarlyWarning {
                    Picker(selection: $countdown.earlyWarningTime, label: Text("Trigger Time").foregroundColor(.primary)) {
                        ForEach([10, 9, 8, 7, 6, 5, 4, 3, 2], id: \.self) { minute in
                            Text("\(minute):00").tag(Double(minute * 60))
                        }
                    }
                }
            }
            
            Section {
                Toggle("Show Final Warning", isOn: $countdown.showsFinalWarning)
                    .foregroundColor(.primary)
                if countdown.showsFinalWarning {
                    Picker(selection: $countdown.finalWarningTime, label: Text("Trigger Time").foregroundColor(.primary)) {
                        ForEach([5, 4, 3, 2, 1, 0], id: \.self) { minute in
                            Text("\(minute):00").tag(Double(minute * 60))
                        }
                    }
                    Toggle("Flash at 0:00", isOn: $countdown.finalWarningFlashes)
                        .foregroundColor(.primary)
                }
            }
        }
        .navigationBarTitle("Edit Timer", displayMode: .inline)
        .toolbar {
            ToolbarItem(placement: .confirmationAction) {
                Button("Done") {
                    presentationMode.wrappedValue.dismiss()
                }
            }
        }
    }
}


struct LengthPicker: View {
    @ObservedObject var countdown: Countdown
    
    #warning("Using strings until number formatter updates without hitting return")
    @State private var minutesString = "5"
    @State private var secondsString = "0"
    
    var body: some View {
        HStack {
            Spacer()
            Text("Minutes:")
            TextField("", text: $minutesString)
                .keyboardType(.numbersAndPunctuation)
                .textFieldStyle(RoundedBorderTextFieldStyle())
                .frame(width: 50)
                .onChange(of: minutesString) { value in
                    if let minutes = Int(value), minutes >= 0 {
                        countdown.length.minutes = minutes
                    } else if value != "" {
                        reloadStrings()
                    }
                }
            Text("Seconds:")
                .padding(.leading)
            TextField("", text: $secondsString)
                .keyboardType(.numbersAndPunctuation)
{'fraction_non_alphanumeric': 0.09700263504611331, 'fraction_numerical': 0.010540184453227932, 'mean_word_length': 1.3170545593285006, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7529499', 'n_tokens_mistral': 1597, 'n_tokens_neox': 1399, 'n_words': 316}