import SwiftUI import Swinject extension CalendarEventSettings { struct RootView: BaseView { let resolver: Resolver @StateObject var state = StateModel() @State private var shouldDisplayHint: Bool = false @State var hintDetent = PresentationDetent.large @State var selectedVerboseHint: AnyView? @State var hintLabel: String? @State private var decimalPlaceholder: Decimal = 0.0 @State private var booleanPlaceholder: Bool = false @Environment(\.colorScheme) var colorScheme @EnvironmentObject var appIcons: Icons private 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 { List { SettingInputSection( decimalValue: $decimalPlaceholder, booleanValue: $state.useCalendar, shouldDisplayHint: $shouldDisplayHint, selectedVerboseHint: Binding( get: { selectedVerboseHint }, set: { selectedVerboseHint = $0.map { AnyView($0) } hintLabel = "Create Events in Calendar" } ), units: state.units, type: .boolean, label: "Create Events in Calendar", miniHint: "Uses calendar events to display current data.", verboseHint: VStack(alignment: .leading, spacing: 10) { Text("Default: OFF").bold() Text( "When enabled, Trio will create a customizable calendar event to keep you notified of your current glucose reading with every successful loop cycle." ) Text( "This is useful if you use CarPlay or a variety of other external services that limit the view of most apps, but allows the calendar app" ) Text( "Once enabled, the available customizations will appear. You can customize with the calendar of your choosing, use of emoji labels, and the inclusion of IOB & COB data." ) Text("Note: Once a new calendar event is created, the previous event will be deleted.") }, headerText: "Diabetes Data as Calendar Event" ) if state.calendarIDs.isNotEmpty, state.useCalendar { Section { VStack { Picker("Choose Calendar", selection: $state.currentCalendarID) { ForEach(state.calendarIDs, id: \.self) { Text($0).tag($0) } } } }.listRowBackground(Color.chart) SettingInputSection( decimalValue: $decimalPlaceholder, booleanValue: $state.displayCalendarEmojis, shouldDisplayHint: $shouldDisplayHint, selectedVerboseHint: Binding( get: { selectedVerboseHint }, set: { selectedVerboseHint = $0.map { AnyView($0) } hintLabel = "Display Emojis as Labels" } ), units: state.units, type: .boolean, label: "Display Emojis as Labels", miniHint: "Emojis used instead of text for data labels.", verboseHint: VStack(alignment: .leading, spacing: 10) { Text("Default: OFF").bold() VStack(alignment: .leading, spacing: 5) { Text( "When enabled, the calendar event created will indicate whether glucose readings are in-range or out-of-range using the following color emojis:" ) Text("🟢: In-Range") Text("🟠: Above-Range") Text("🔴: Below-Range") } VStack(alignment: .leading, spacing: 5) { Text( "If \"Display IOB and COB\" is also enabled, \"IOB\" and \"COB\" will be replaced with the following emojis:" ) Text("💉: IOB") Text("🥨: COB") } } ) SettingInputSection( decimalValue: $decimalPlaceholder, booleanValue: $state.displayCalendarIOBandCOB, shouldDisplayHint: $shouldDisplayHint, selectedVerboseHint: Binding( get: { selectedVerboseHint }, set: { selectedVerboseHint = $0.map { AnyView($0) } hintLabel = "Display IOB and COB" } ), units: state.units, type: .boolean, label: "Display IOB and COB", miniHint: "Include IOB & COB in the calendar event data.", verboseHint: VStack(alignment: .leading, spacing: 10) { Text("Default: OFF").bold() Text( "When enabled, Trio will include the current IOB and COB values, along with the current glucose reading, in each calendar event created." ) } ) } else if state.useCalendar { if #available(iOS 17.0, *) { Text( "If you are not seeing calendars to choose here, please go to Settings -> Trio -> Calendars and change permissions to \"Full Access\"" ).font(.footnote) Button("Open Settings") { // Get the settings URL and open it if let url = URL(string: UIApplication.openSettingsURLString) { UIApplication.shared.open(url) } } } } } .listSectionSpacing(sectionSpacing) .sheet(isPresented: $shouldDisplayHint) { SettingInputHintView( hintDetent: $hintDetent, shouldDisplayHint: $shouldDisplayHint, hintLabel: hintLabel ?? "", hintText: selectedVerboseHint ?? AnyView(EmptyView()), sheetTitle: "Help" ) } .scrollContentBackground(.hidden).background(color) .onAppear(perform: configureView) .navigationTitle("Calendar Events") .navigationBarTitleDisplayMode(.automatic) } } }