import SwiftUI /// The "How Best Value works" explanation as its own sheet. /// /// It used to sit inline in the Key sheet as a `Section`; it is one shared view /// now so the Key sheet and the More info sheet can both open it, and the copy is /// unchanged (the same `Localizable.strings` keys are reused — the old section /// header string is the sheet's title). struct HowBestValueSheet: View { @Environment(\.dismiss) private var dismiss var body: some View { NavigationStack { List { Section { VStack(alignment: .leading, spacing: 10) { Text("Best Value compares each station with the closest station by journey distance. It works out what you could save at the pump, then takes off the fuel used for the extra return journey.") Text("Your fill-up amount and MPG are used to show whether you could save overall.") } .font(.subheadline) .padding(.vertical, 4) } Section("The working, step by step") { VStack(alignment: .leading, spacing: 12) { step("1. The baseline", "The closest station by journey distance. It is the trip you would make anyway, so everything else is measured against it.") step("2. The return trip", "For each station we work out the journey there and back. Where the roads have been measured we use the real driving route; until then we double the straight-line distance and mark the figure “Approx.”.") step("3. Extra return travel", "This station's return trip minus the baseline's. It is the extra you add on top of the journey you were already making — not the whole trip. Because both figures are return trips, it can read larger than the one-way distance shown above the map.") step("4. Extra driving cost", "What that extra distance costs in fuel: the extra miles, divided by your MPG, priced at the station you are driving to.") step("5. Fuel-price saving", "What the difference in price per litre is worth on your fill-up.") step("6. Total", "The fuel-price saving minus the extra driving cost. If the drive costs more than the price saves, the total is shown as an extra cost instead, and the station is not Best Value.") step("7. Best Value", "The total clears the minimum saving you set in Settings → Fuel Savings.") } .font(.subheadline) .padding(.vertical, 4) } Section { VStack(alignment: .leading, spacing: 10) { Text("With a £ budget you spend that amount at each station; the litres differ by station. Savings compare those litres with the same quantity at your closest station, then deduct extra journey fuel. You do not receive cash back.") Text("With Litres, every station is compared for the fixed quantity you selected.") Text("Results are marked “Approx.” until road distances are available.") .foregroundStyle(.secondary) } .font(.subheadline) .padding(.vertical, 4) } } .navigationTitle("How Best Value works") .navigationBarTitleDisplayMode(.inline) .toolbar { ToolbarItem(placement: .confirmationAction) { Button("Done") { dismiss() } } } } .presentationDetents([.fraction(0.72)]) .presentationBackground(Color(UIColor.systemGroupedBackground)) } /// One numbered step: a lead-in, then the plain explanation. Same words /// either way — this only sets the hierarchy. private func step(_ title: String, _ explanation: String) -> some View { VStack(alignment: .leading, spacing: 2) { Text(title) .font(.subheadline.weight(.semibold)) Text(explanation) .foregroundStyle(.secondary) } } } /// The row that opens `HowBestValueSheet`. A tappable row with a chevron, like /// the other rows in both sheets. `.buttonStyle(.plain)` keeps it from becoming a /// row-wide tap target that could swallow a neighbouring control (see the /// two-buttons-in-one-row rule). struct HowBestValueRow: View { let action: () -> Void var body: some View { Button(action: action) { HStack(spacing: 8) { Text("How Best Value works") Spacer(minLength: 8) Image(systemName: "chevron.forward") .font(.footnote.weight(.semibold)) .foregroundStyle(.tertiary) } } .buttonStyle(.plain) } } #if DEBUG /// QA hook support: `-showBestValueInfo` opens this sheet without a tap, so it can /// be screenshotted (simctl has no tap command) — the same pattern as /// `-showKeySheet` / `-showDetail`. enum BestValueInfoQA { static var isRequested: Bool { ProcessInfo.processInfo.arguments.contains("-showBestValueInfo") } } #endif