| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- import SwiftUI
- import Swinject
- extension PumpConfig {
- struct RootView: BaseView {
- let resolver: Resolver
- let displayClose: Bool
- @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
- @State var showPumpSelection: 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
- )
- }
- var body: some View {
- NavigationView {
- Form {
- Section(
- header: Text("Pump Integration to Trio"),
- content: {
- if let pumpState = state.pumpState {
- Button {
- state.setupPump = true
- } label: {
- HStack {
- Image(uiImage: pumpState.image ?? UIImage()).padding()
- Text(pumpState.name)
- }
- }
- if state.alertNotAck {
- Spacer()
- Button("Acknowledge all alerts") { state.ack() }
- }
- } else {
- VStack {
- Button {
- showPumpSelection.toggle()
- } label: {
- Text("Add Pump")
- .font(.title3) }
- .frame(maxWidth: .infinity, alignment: .center)
- .buttonStyle(.bordered)
- HStack(alignment: .top) {
- Text(
- "Pair a compatible pump with Trio. See details for available devices."
- )
- .font(.footnote)
- .foregroundColor(.secondary)
- .lineLimit(nil)
- Spacer()
- Button(
- action: {
- hintLabel = "Pump Pairing to Trio"
- selectedVerboseHint =
- "Explanation… limitation… etc."
- shouldDisplayHint.toggle()
- },
- label: {
- HStack {
- Image(systemName: "questionmark.circle")
- }
- }
- ).buttonStyle(BorderlessButtonStyle())
- }.padding(.top)
- }.padding(.vertical)
- }
- }
- )
- .padding(.top)
- .listRowBackground(Color.chart)
- if state.pumpState != nil {
- Section {
- Text("Delivery Limits & DIA")
- .navigationLink(to: .pumpSettingsEditor, from: self)
- }.listRowBackground(Color.chart)
- }
- }
- .scrollContentBackground(.hidden).background(color)
- .onAppear(perform: configureView)
- .navigationTitle("Insulin Pump")
- .navigationBarTitleDisplayMode(.automatic)
- .navigationBarItems(leading: displayClose ? Button("Close", action: state.hideModal) : nil)
- .sheet(isPresented: $state.setupPump) {
- if let pumpManager = state.provider.apsManager.pumpManager {
- PumpSettingsView(
- pumpManager: pumpManager,
- bluetoothManager: state.provider.apsManager.bluetoothManager!,
- completionDelegate: state,
- setupDelegate: state
- )
- } else {
- PumpSetupView(
- pumpType: state.setupPumpType,
- pumpInitialSettings: state.initialSettings,
- bluetoothManager: state.provider.apsManager.bluetoothManager!,
- completionDelegate: state,
- setupDelegate: state
- )
- }
- }
- .sheet(isPresented: $shouldDisplayHint) {
- SettingInputHintView(
- hintDetent: $hintDetent,
- shouldDisplayHint: $shouldDisplayHint,
- hintLabel: hintLabel ?? "",
- hintText: selectedVerboseHint ?? "",
- sheetTitle: "Help"
- )
- }
- .confirmationDialog("Pump Model", isPresented: $showPumpSelection) {
- Button("Medtronic") { state.addPump(.minimed) }
- Button("Omnipod Eros") { state.addPump(.omnipod) }
- Button("Omnipod Dash") { state.addPump(.omnipodBLE) }
- Button("Pump Simulator") { state.addPump(.simulator) }
- } message: { Text("Select Pump Model") }
- }
- }
- }
- }
|