Repository Public
1//2// Food-Ka iOS v23// File: FoodKa/Features/Basket/StoreModeView.swift4// Description: mode « à l'épicerie » — la liste en gros texte, triée par rayon, une case à cocher par article,5// l'écran qui reste allumé. Fonctionne sans réseau.6//7// Author: Simon-Pierre Boucher8// Contact: contact@spboucher.ai9//1011import SwiftUI12import UIKit1314struct StoreModeView: View {15 @Environment(AppModel.self) private var model16 @Environment(GroceryList.self) private var list1718 var body: some View {19 NavigationStack {20 ScrollView {21 LazyVStack(alignment: .leading, spacing: 0) {22 HStack(alignment: .firstTextBaseline) {23 Text(list.remaining == 0 ? "Tout est coché." : "\(list.remaining) à trouver")24 .font(.editorial(28)).foregroundStyle(Theme.ink)25 .accessibilityIdentifier("store-mode-remaining")26 Spacer()27 Text("\(list.count - list.remaining) sur \(list.count)").font(.title3).monospacedDigit().foregroundStyle(Theme.ink3)28 }29 .padding(.top, 8)30 // l'avancement, sur une tablette31 GeometryReader { geo in32 ZStack(alignment: .leading) {33 Capsule().fill(Theme.line2)34 Capsule().fill(Theme.shelf)35 .frame(width: list.count == 0 ? 0 : geo.size.width * CGFloat(list.count - list.remaining) / CGFloat(list.count))36 }37 }38 .frame(height: 5).padding(.top, 10)39 .accessibilityHidden(true)4041 ForEach(list.byCategory, id: \.category) { group in42 HStack(spacing: 10) {43 Image(Category.icon(name: group.category)).resizable().scaledToFit().frame(width: 22, height: 22).foregroundStyle(Theme.ink3)44 Text(group.category).eyebrowStyle()45 }46 .padding(.top, 30).padding(.bottom, 4)47 .accessibilityAddTraits(.isHeader)48 ForEach(group.items) { item in49 row(item)50 Hairline()51 }52 }53 if list.isEmpty {54 EmptyShelf(title: "La liste est vide", message: "Ajoutez des articles avant de partir à l'épicerie.")55 }56 }57 .pageColumn()58 .padding(.bottom, 40)59 }60 .paper()61 .navigationTitle("À l'épicerie")62 .navigationBarTitleDisplayMode(.inline)63 .toolbar {64 ToolbarItem(placement: .topBarLeading) {65 Button("Fermer") { model.storeMode = false }.accessibilityIdentifier("store-mode-close")66 }67 ToolbarItem(placement: .topBarTrailing) {68 Button("Tout décocher") { list.uncheckAll() }.disabled(list.remaining == list.count)69 }70 }71 }72 // l'écran reste allumé pendant les courses73 .onAppear { UIApplication.shared.isIdleTimerDisabled = true }74 .onDisappear { UIApplication.shared.isIdleTimerDisabled = false }75 }7677 private func row(_ item: GroceryItem) -> some View {78 Button {79 list.toggleChecked(item.id)80 Haptics.tap()81 } label: {82 HStack(alignment: .center, spacing: 16) {83 ZStack {84 RoundedRectangle(cornerRadius: 7, style: .continuous)85 .fill(item.checked ? Theme.shelf : Color.clear)86 RoundedRectangle(cornerRadius: 7, style: .continuous)87 .strokeBorder(item.checked ? Theme.shelf : Theme.ink3, lineWidth: 2)88 if item.checked {89 Image(systemName: "checkmark").font(.system(size: 17, weight: .bold)).foregroundStyle(Theme.bg)90 }91 }92 .frame(width: 34, height: 34)93 VStack(alignment: .leading, spacing: 3) {94 Text(item.title)95 .font(.system(size: Font.scaled(22), weight: .medium, design: .serif))96 .strikethrough(item.checked, color: Theme.ink3)97 .foregroundStyle(item.checked ? Theme.ink3 : Theme.ink)98 .multilineTextAlignment(.leading).fixedSize(horizontal: false, vertical: true)99 if let s = item.product?.brandAndSize {100 Text(s).font(.body).foregroundStyle(Theme.ink3).multilineTextAlignment(.leading)101 }102 if let p = item.product, !item.checked {103 Text("\(Fmt.price(p.price)) chez \(p.storeName)").font(.subheadline).monospacedDigit().foregroundStyle(Theme.ink3)104 }105 }106 Spacer(minLength: 8)107 if item.quantity != 1 {108 Text("× " + Fmt.quantity(item.quantity)).font(.system(size: Font.scaled(22), weight: .semibold)).monospacedDigit()109 .foregroundStyle(item.checked ? Theme.ink3 : Theme.ink)110 }111 }112 .frame(minHeight: 64)113 .padding(.vertical, 8)114 .contentShape(Rectangle())115 }116 .buttonStyle(.plain)117 .accessibilityElement(children: .ignore)118 .accessibilityLabel(item.title + (item.quantity != 1 ? ", quantité \(Fmt.quantity(item.quantity))" : "") + (item.product?.brandAndSize.map { ", " + $0 } ?? ""))119 .accessibilityValue(item.checked ? "coché" : "à trouver")120 .accessibilityAddTraits(.isButton)121 .accessibilityIdentifier("check-\(item.title)")122 }123}124