Almost done
This commit is contained in:
@@ -17,6 +17,7 @@ struct PizzaProductDetailSheet: View {
|
||||
@State var flavorAddonQuantities: [String: [String: Int]] = [:]
|
||||
@State var selectedFlavorForAddons: StoreCatalogProduct? = nil
|
||||
@State var quantity: Int = 1
|
||||
@State var expandedStep: Int = 0
|
||||
|
||||
var flavors: [StoreCatalogProduct] {
|
||||
category.products
|
||||
@@ -45,7 +46,7 @@ struct PizzaProductDetailSheet: View {
|
||||
return resolveImageURL(firstImage)
|
||||
}
|
||||
|
||||
private var selectedSize: StorePizzaSize? {
|
||||
var selectedSize: StorePizzaSize? {
|
||||
guard let selectedSizeId else { return nil }
|
||||
return sizes.first(where: { $0.id == selectedSizeId })
|
||||
}
|
||||
@@ -76,7 +77,7 @@ struct PizzaProductDetailSheet: View {
|
||||
isCrustReady
|
||||
}
|
||||
|
||||
private var selectedFlavorProducts: [StoreCatalogProduct] {
|
||||
var selectedFlavorProducts: [StoreCatalogProduct] {
|
||||
flavors
|
||||
.filter { selectedFlavorIds.contains($0.id) }
|
||||
.sorted { $0.name < $1.name }
|
||||
@@ -102,12 +103,12 @@ struct PizzaProductDetailSheet: View {
|
||||
}
|
||||
|
||||
private var basePizzaPrice: Double {
|
||||
selectedFlavorProducts
|
||||
.map { flavor in
|
||||
guard let selectedSizeId else { return flavor.price ?? 0 }
|
||||
return flavor.pizzaPrices[selectedSizeId] ?? flavor.price ?? 0
|
||||
}
|
||||
.max() ?? 0
|
||||
let prices = selectedFlavorProducts.map { flavor in
|
||||
guard let selectedSizeId else { return flavor.price ?? 0 }
|
||||
return flavor.pizzaPrices[selectedSizeId] ?? flavor.price ?? 0
|
||||
}
|
||||
guard prices.isEmpty == false else { return 0 }
|
||||
return prices.reduce(0, +) / Double(prices.count)
|
||||
}
|
||||
|
||||
private var unitPrice: Double {
|
||||
@@ -179,6 +180,34 @@ struct PizzaProductDetailSheet: View {
|
||||
return chunks.isEmpty ? nil : chunks.joined(separator: " • ")
|
||||
}
|
||||
|
||||
private var pizzaChoices: [String] {
|
||||
var choices: [String] = []
|
||||
if let sizeName = selectedSize?.name {
|
||||
let sizePrice = basePizzaPrice
|
||||
if sizePrice > 0 {
|
||||
choices.append("Tamanho: \(sizeName) (+\(formatCurrency(sizePrice)))")
|
||||
} else {
|
||||
choices.append("Tamanho: \(sizeName)")
|
||||
}
|
||||
}
|
||||
if let crustName = selectedCrust?.name, crustName.isEmpty == false {
|
||||
let mod = crustPriceModifier
|
||||
if mod > 0 {
|
||||
choices.append("Borda: \(crustName) (+\(formatCurrency(mod)))")
|
||||
} else {
|
||||
choices.append("Borda: \(crustName)")
|
||||
}
|
||||
}
|
||||
if let doughName = selectedDoughName, doughName.isEmpty == false {
|
||||
choices.append("Massa: \(doughName)")
|
||||
}
|
||||
let flavorCount = selectedFlavorProducts.count
|
||||
for flavor in selectedFlavorProducts {
|
||||
choices.append(flavorCount > 1 ? "Meio \(flavor.name)" : flavor.name)
|
||||
}
|
||||
return choices
|
||||
}
|
||||
|
||||
private var addButtonTitle: String {
|
||||
if canConfirm == false {
|
||||
return "Selecione as opções"
|
||||
@@ -190,8 +219,16 @@ struct PizzaProductDetailSheet: View {
|
||||
ScrollView(showsIndicators: false) {
|
||||
VStack(alignment: .leading, spacing: 16) {
|
||||
screenHeader
|
||||
AsyncStoreImage(imageURL: representativeImage)
|
||||
Rectangle()
|
||||
.fill(AppColors.brandSoft)
|
||||
.frame(maxWidth: .infinity)
|
||||
.frame(height: 220)
|
||||
.overlay(
|
||||
Image("placeholder-pizza")
|
||||
.resizable()
|
||||
.scaledToFill()
|
||||
.clipped()
|
||||
)
|
||||
.clipShape(RoundedRectangle(cornerRadius: AppLayout.radiusXL, style: .continuous))
|
||||
|
||||
Text("Pizza de varios sabores")
|
||||
@@ -207,18 +244,9 @@ struct PizzaProductDetailSheet: View {
|
||||
.foregroundStyle(AppColors.primary)
|
||||
|
||||
stepSizes
|
||||
|
||||
if selectedSizeId != nil {
|
||||
stepDoughs
|
||||
}
|
||||
|
||||
if isDoughReady {
|
||||
stepCrusts
|
||||
}
|
||||
|
||||
if canShowFlavors {
|
||||
stepFlavors
|
||||
}
|
||||
if selectedSizeId != nil { stepDoughs }
|
||||
if isDoughReady { stepCrusts }
|
||||
if canShowFlavors { stepFlavors }
|
||||
}
|
||||
.padding(20)
|
||||
.padding(.bottom, 90)
|
||||
@@ -266,6 +294,7 @@ struct PizzaProductDetailSheet: View {
|
||||
name: "Pizza de varios sabores",
|
||||
imageURL: representativeImage,
|
||||
details: selectedDetailsText,
|
||||
choices: pizzaChoices.isEmpty ? nil : pizzaChoices,
|
||||
addons: selectedAddonsPayload,
|
||||
quantity: quantity,
|
||||
unitPrice: unitPrice
|
||||
|
||||
Reference in New Issue
Block a user