import SwiftUI import Swinject extension PumpSettingsEditor { struct RootView: BaseView { let resolver: Resolver @StateObject var state = StateModel() @State private var shouldDisplayHint: Bool = false @State var hintDetent = PresentationDetent.large @State var selectedVerboseHint: String? @State var hintLabel: String? @State private var decimalPlaceholder: Decimal = 0.0 @State private var booleanPlaceholder: Bool = false @Environment(\.colorScheme) var colorScheme var color: LinearGradient { colorScheme == .dark ? LinearGradient( gradient: Gradient(colors: [ Color.bgDarkBlue, Color.bgDarkerDarkBlue ]), startPoint: .top, endPoint: .bottom ) : LinearGradient( gradient: Gradient(colors: [Color.gray.opacity(0.1)]), startPoint: .top, endPoint: .bottom ) } private var formatter: NumberFormatter { let formatter = NumberFormatter() formatter.numberStyle = .decimal return formatter } var body: some View { Form { SettingInputSection( decimalValue: $state.maxBolus, booleanValue: $booleanPlaceholder, shouldDisplayHint: $shouldDisplayHint, selectedVerboseHint: Binding( get: { selectedVerboseHint }, set: { selectedVerboseHint = $0 hintLabel = "Max Bolus" } ), units: state.units, type: .decimal("maxBolus"), label: "Max Bolus", miniHint: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr.", verboseHint: "Max Bolus… bla bla bla" ) SettingInputSection( decimalValue: $state.maxBasal, booleanValue: $booleanPlaceholder, shouldDisplayHint: $shouldDisplayHint, selectedVerboseHint: Binding( get: { selectedVerboseHint }, set: { selectedVerboseHint = $0 hintLabel = "Max Basal" } ), units: state.units, type: .decimal("maxBasal"), label: "Max Basal", miniHint: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr.", verboseHint: "Max Basal… bla bla bla" ) SettingInputSection( decimalValue: $state.dia, booleanValue: $booleanPlaceholder, shouldDisplayHint: $shouldDisplayHint, selectedVerboseHint: Binding( get: { selectedVerboseHint }, set: { selectedVerboseHint = $0 hintLabel = "Duration of Insulin Action" } ), units: state.units, type: .decimal("dia"), label: "Duration of Insulin Action", miniHint: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr.", verboseHint: "Duration of Insulin Action… bla bla bla" ) Section { HStack { if state.syncInProgress { ProgressView().padding(.trailing, 10) } Button { let impactHeavy = UIImpactFeedbackGenerator(style: .heavy) impactHeavy.impactOccurred() state.save() } label: { Text(state.syncInProgress ? "Saving..." : "Save") } .disabled(state.syncInProgress || !state.hasChanged) .frame(maxWidth: .infinity, alignment: .center) .tint(.white) } }.listRowBackground(state.syncInProgress || !state.hasChanged ? Color(.systemGray4) : Color(.systemBlue)) } .sheet(isPresented: $shouldDisplayHint) { SettingInputHintView( hintDetent: $hintDetent, shouldDisplayHint: $shouldDisplayHint, hintLabel: hintLabel ?? "", hintText: selectedVerboseHint ?? "", sheetTitle: "Help" ) } .scrollContentBackground(.hidden).background(color) .onAppear(perform: configureView) .navigationTitle("Delivery Limits") .navigationBarTitleDisplayMode(.automatic) } } }