// LoopFollow
// MissedBolusAlarmEditor.swift

import SwiftUI

struct MissedBolusAlarmEditor: View {
    @Binding var alarm: Alarm

    var body: some View {
        Group {
            InfoBanner(
                text: String(localized: "Alerts when carbs are logged but no bolus is delivered within the delay below.  Allows small-carb / treatment exclusions and pre-bolus detection."),
                alarmType: alarm.type
            )

            AlarmGeneralSection(alarm: $alarm)

            AlarmStepperSection(
                header: String(localized: "Delay"),
                footer: String(localized: "Minutes to wait after the carb entry before checking for a bolus."),
                title: String(localized: "Delay"),
                range: 5 ... 60,
                step: 5,
                unitLabel: String(localized: "min"),
                value: $alarm.monitoringWindow
            )

            AlarmStepperSection(
                header: String(localized: "Pre-bolus"),
                footer: String(localized: "Count boluses given up to this many minutes before the carb entry as valid."),
                title: String(localized: "Pre-Bolus Time"),
                range: 0 ... 45,
                step: 5,
                unitLabel: String(localized: "min"),
                value: $alarm.predictiveMinutes
            )

            AlarmStepperSection(
                header: String(localized: "Ignore small boluses"),
                footer: String(localized: "Boluses at or below this size are ignored."),
                title: String(localized: "At or Below"),
                range: 0.05 ... 2,
                step: 0.05,
                unitLabel: String(localized: "Units"),
                value: $alarm.delta
            )

            AlarmStepperSection(
                header: String(localized: "Ignore small carbs"),
                footer: String(localized: "Carb entries at or below this amount will not trigger the alarm."),
                title: String(localized: "At or Below"),
                range: 0 ... 15,
                step: 1,
                unitLabel: String(localized: "Grams"),
                value: $alarm.threshold
            )

            AlarmBGLimitSection(
                header: String(localized: "Ignore low BG"),
                footer: String(localized: "Only alert if the current BG is above this value."),
                toggleText: String(localized: "Use BG Limit"),
                pickerTitle: String(localized: "Above"),
                range: 40 ... 140,
                defaultOnValue: 70,
                value: $alarm.aboveBG
            )

            AlarmActiveSection(alarm: $alarm)
            AlarmAudioSection(alarm: $alarm)
            AlarmSnoozeSection(alarm: $alarm)
        }
    }
}
