// LoopFollow
// IOBAlarmEditor.swift

import SwiftUI

struct IOBAlarmEditor: View {
    @Binding var alarm: Alarm

    var body: some View {
        Group {
            InfoBanner(
                text: String(localized: "Alerts when insulin-on-board is high, or when several boluses in quick succession exceed the limits you set."),
                alarmType: alarm.type
            )

            AlarmGeneralSection(alarm: $alarm)

            AlarmStepperSection(
                header: String(localized: "Boluses Size Limit"),
                footer: String(localized: "This counts only boluses larger than this size."),
                title: String(localized: "Above"),
                range: 0.1 ... 20,
                step: 0.1,
                unitLabel: String(localized: "Units"),
                value: $alarm.delta
            )

            AlarmStepperSection(
                header: String(localized: "Bolus Count"),
                footer: String(localized: "Number of qualifying boluses needed to trigger."),
                title: String(localized: "Count"),
                range: 1 ... 10,
                step: 1,
                unitLabel: String(localized: "Boluses"),
                value: $alarm.monitoringWindow
            )

            AlarmStepperSection(
                header: String(localized: "Time Window"),
                footer: String(localized: "How far back to look for those boluses."),
                title: String(localized: "Time"),
                range: 5 ... 120,
                step: 5,
                unitLabel: String(localized: "min"),
                value: $alarm.predictiveMinutes
            )

            AlarmStepperSection(
                header: String(localized: "Insulin On Board"),
                footer: String(localized: "Alert if current IOB or total boluses reach this."),
                title: String(localized: "IOB Above"),
                range: 1 ... 20,
                step: 0.5,
                unitLabel: String(localized: "Units"),
                value: $alarm.threshold
            )

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