Files
LektorenPlan/Sources/LektorenPlan/Views/PlanResultSheet.swift
T

166 lines
9.1 KiB
Swift

import SwiftUI
import LektorenPlanCore
struct PlanResultSheet: View {
@EnvironmentObject private var model: PlanModel
@Environment(\.dismiss) private var dismiss
var body: some View {
VStack(spacing: 0) {
if let result = model.planResult {
let canOfferBeyond = !result.unfilled.isEmpty
&& !model.planResultUsedBeyond
&& model.people.contains { $0.active && $0.allowBeyondPreferences }
SheetHeader(
icon: result.unfilled.isEmpty ? "checkmark.seal" : "exclamationmark.triangle",
title: result.unfilled.isEmpty ? "Planung abgeschlossen" : "Planung mit Lücken",
subtitle: result.message,
tint: result.unfilled.isEmpty ? LP.success : LP.open
)
Hairline()
ScrollView {
VStack(alignment: .leading, spacing: 18) {
HStack(spacing: 12) {
resultTile(
icon: "checkmark.circle",
value: "\(result.filledCount)",
label: "neu besetzte Dienste",
tint: LP.success
)
resultTile(
icon: "circle.dashed",
value: "\(result.unfilled.count)",
label: "offene Dienste",
tint: LP.open
)
resultTile(
icon: "person.2",
value: "\(model.stats.assignmentCount)",
label: "Einsätze im Zeitraum",
tint: LP.accent
)
}
if result.unfilled.isEmpty {
HStack(alignment: .top, spacing: 9) {
Image(systemName: "sparkles")
.foregroundStyle(LP.gold)
Text("Alle Dienste im gewählten Zeitraum konnten unter Berücksichtigung von Abwesenheiten, Einsatztagen und Monatslimits besetzt werden. Gesperrte Einsätze wurden nicht verändert.")
.font(.system(size: 10.5))
.foregroundStyle(LP.inkSecondary)
.fixedSize(horizontal: false, vertical: true)
}
.padding(12)
.background(RoundedRectangle(cornerRadius: 10).fill(LP.successSoft.opacity(0.6)))
} else {
FormSection(
title: "Nicht besetzbare Dienste",
subtitle: "Die genannten Gründe zeigen, warum keine geeignete Person gefunden wurde."
) {
VStack(spacing: 0) {
ForEach(Array(result.unfilled.enumerated()), id: \.element.id) { index, slot in
HStack(alignment: .top, spacing: 10) {
VStack(alignment: .leading, spacing: 1) {
Text(DayMath.shortWeekdayName(slot.service.date).uppercased())
.font(.system(size: 7.5, weight: .bold, design: .rounded))
.foregroundStyle(LP.inkTertiary)
Text("\(DayMath.dayNumber(slot.service.date)).")
.font(.system(size: 14, weight: .semibold, design: .serif))
.foregroundStyle(LP.ink)
Text(DayMath.shortMonthName(slot.service.date))
.font(.system(size: 8))
.foregroundStyle(LP.inkTertiary)
}
.frame(width: 34)
VStack(alignment: .leading, spacing: 2) {
HStack(spacing: 5) {
Text(slot.service.timeLabel)
.font(.system(size: 9.5, weight: .bold, design: .rounded))
.foregroundStyle(LP.accent)
Text(slot.service.title)
.font(.system(size: 10.5, weight: .medium))
.foregroundStyle(LP.ink)
}
Text("\(slot.churchName) · \(slot.role.title)")
.font(.system(size: 9))
.foregroundStyle(LP.inkTertiary)
Text(slot.reason)
.font(.system(size: 9.5))
.foregroundStyle(LP.open)
}
Spacer()
}
.padding(.horizontal, 10)
.padding(.vertical, 7)
.background(index % 2 == 0 ? LP.cardMuted.opacity(0.4) : Color.clear)
}
}
.clipShape(RoundedRectangle(cornerRadius: 9))
.overlay(RoundedRectangle(cornerRadius: 9).strokeBorder(LP.line.opacity(0.55), lineWidth: 0.8))
}
if canOfferBeyond {
let flagged = model.people.filter { $0.active && $0.allowBeyondPreferences }
HStack(alignment: .top, spacing: 9) {
Image(systemName: "arrow.up.right.circle")
.foregroundStyle(LP.burgundy)
Text("\(flagged.count) \(flagged.count == 1 ? "Person hat" : "Personen haben") sich bereit erklärt, nach Rückfrage auch über die eigenen Präferenzen hinaus eingeplant zu werden. Diese Einsätze werden im Plan besonders gekennzeichnet.")
.font(.system(size: 10.5))
.foregroundStyle(LP.inkSecondary)
.fixedSize(horizontal: false, vertical: true)
}
.padding(12)
.background(RoundedRectangle(cornerRadius: 10).fill(LP.burgundySoft.opacity(0.5)))
}
}
}
.padding(22)
}
SheetFooter {
if canOfferBeyond {
PrimaryActionButton(title: "Über Präferenzen hinaus planen", icon: "arrow.up.right") {
_ = model.autoPlan(replaceExisting: false, allowBeyond: true)
}
}
Spacer()
SecondaryActionButton(title: "Statistik ansehen", icon: "chart.xyaxis.line") {
model.planResult = nil
model.section = .statistics
dismiss()
}
PrimaryActionButton(title: "Schließen", icon: "checkmark") {
model.planResult = nil
dismiss()
}
}
} else {
ProgressView()
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
}
.sheetSurface(width: 620, height: 560)
}
private func resultTile(icon: String, value: String, label: String, tint: Color) -> some View {
VStack(alignment: .leading, spacing: 4) {
Image(systemName: icon)
.font(.system(size: 13, weight: .semibold))
.foregroundStyle(tint)
Text(value)
.font(.system(size: 22, weight: .bold, design: .rounded))
.foregroundStyle(LP.ink)
Text(label)
.font(.system(size: 9))
.foregroundStyle(LP.inkTertiary)
}
.frame(maxWidth: .infinity, alignment: .leading)
.padding(12)
.background(RoundedRectangle(cornerRadius: 10).fill(LP.cardMuted))
.overlay(RoundedRectangle(cornerRadius: 10).strokeBorder(LP.line.opacity(0.55), lineWidth: 0.8))
}
}