SPB Git

Repository Public

PriceDropsView.swift 4.0 KB 95 lines swift

1//2//  Auto-Ka iOS v23//  File: AutoKa/Features/Market/PriceDropsView.swift4//  Description: baisses de prix récentes — nombre, part, baisse médiane, marques, plus fortes baisses.5//6//  Author: Simon-Pierre Boucher7//  Contact: contact@spboucher.ai8//910import SwiftUI1112struct PriceDropsView: View {13    @State private var days = 301415    private static let windows: [(value: Int, label: String)] = [(7, "7 j"), (30, "30 j"), (90, "90 j")]1617    var body: some View {18        let d = days19        Loadable(id: "baisses-\(d)") {20            try await APIClient.shared.priceDrops(days: d, limit: 24)21        } content: { data in22            PriceDropsContent(data: data, days: $days)23        }24        .navigationTitle("Baisses de prix")25        .navigationBarTitleDisplayMode(.inline)26    }2728    fileprivate static var options: [(value: Int, label: String)] { windows }29}3031private struct PriceDropsContent: View {32    let data: PriceDrops33    @Binding var days: Int34    @Environment(AppModel.self) private var model3536    var body: some View {37        Page {38            VStack(alignment: .leading, spacing: 14) {39                Text("Baisses de prix").font(.editorial(28)).foregroundStyle(Theme.ink).accessibilityAddTraits(.isHeader)40                Text("Annonces dont le prix demandé a baissé à sa dernière variation, depuis \(data.days ?? days) jours.")41                    .font(.subheadline).foregroundStyle(Theme.ink2).fixedSize(horizontal: false, vertical: true)42                SlidingSegmented(selection: $days, options: PriceDropsView.options, label: "Période")43            }44            VStack(alignment: .leading, spacing: 16) {45                Rule()46                StatGrid {47                    StatFigure(value: Fmt.int(data.count), label: "annonces dont le prix a baissé",48                               detail: data.sharePct.map { "\(Fmt.pct($0)) des voitures en ligne" })49                    if let p = data.medianDropPct {50                        StatFigure(value: Fmt.signedPct(p), label: "baisse médiane",51                                   detail: data.medianDrop.map { Fmt.signedMoney($0) })52                    }53                }54                Button {55                    var f = SearchFilters()56                    f.priceDrop = true57                    model.search(f, sort: .drop)58                } label: {59                    Text("Voir toutes les baisses")60                }61                .buttonStyle(PrimaryButtonStyle())62            }63            if let rows = data.byMake, !rows.isEmpty {64                let top = Array(rows.prefix(10)), maxN = Double(top.map(\.n).max() ?? 1)65                VStack(alignment: .leading, spacing: 14) {66                    SectionHeader("Par marque", subtitle: "Nombre d'annonces dont le prix a baissé.")67                    VStack(spacing: 12) {68                        ForEach(top) { r in69                            Button {70                                var f = SearchFilters.make(r.make)71                                f.priceDrop = true72                                model.search(f, sort: .drop)73                            } label: {74                                BarRow(label: r.make, value: Double(r.n), max: maxN)75                                    .frame(minHeight: 44)76                                    .contentShape(Rectangle())77                            }78                            .buttonStyle(.plain)79                            .accessibilityHint("Lance la recherche")80                        }81                    }82                }83            }84            VStack(alignment: .leading, spacing: 16) {85                SectionHeader("Plus fortes baisses", subtitle: "Une très forte baisse peut corriger une erreur de saisie : vérifier l'annonce d'origine.")86                if data.listings.isEmpty {87                    EmptyState(title: "Aucune baisse sur cette période", message: "Essayez une période plus longue.")88                } else {89                    VehicleGrid(vehicles: data.listings)90                }91            }92        }93    }94}95
Files main
Menu

Theme