144 lines
3.8 KiB
Swift
144 lines
3.8 KiB
Swift
import SwiftUI
|
|
|
|
struct DashboardView: View {
|
|
|
|
@StateObject private var viewModel = DashboardViewModel()
|
|
|
|
var body: some View {
|
|
ScrollView {
|
|
VStack(alignment: .leading, spacing: 24) {
|
|
header
|
|
nextDoseCard
|
|
todaySection
|
|
}
|
|
.padding(20)
|
|
}
|
|
.background(Color.appSecondary.ignoresSafeArea())
|
|
.navigationBarHidden(true)
|
|
.task {
|
|
await viewModel.loadDashboard()
|
|
}
|
|
.refreshable {
|
|
await viewModel.loadDashboard()
|
|
}
|
|
}
|
|
|
|
private var header: some View {
|
|
VStack(alignment: .leading, spacing: 6) {
|
|
Text("O seu plano")
|
|
.font(.jakartaBold24)
|
|
.foregroundStyle(Color.appTextPrimary)
|
|
Text("A sua medicacao de hoje")
|
|
.font(.jakartaRegular16)
|
|
.foregroundStyle(Color.appTextPrimary.opacity(0.65))
|
|
}
|
|
}
|
|
|
|
@ViewBuilder
|
|
private var nextDoseCard: some View {
|
|
if viewModel.isLoading && viewModel.prescriptions.isEmpty {
|
|
ProgressView()
|
|
.frame(maxWidth: .infinity, minHeight: 156)
|
|
} else if let errorMessage = viewModel.errorMessage {
|
|
VStack(alignment: .leading, spacing: 12) {
|
|
Text(errorMessage)
|
|
.font(.jakartaRegular16)
|
|
.foregroundStyle(.red)
|
|
Button("Tentar novamente") {
|
|
Task { await viewModel.loadDashboard() }
|
|
}
|
|
.font(.jakartaBold16)
|
|
.foregroundStyle(Color.appBackground)
|
|
}
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
.padding(20)
|
|
.background(.white)
|
|
.clipShape(RoundedRectangle(cornerRadius: 8))
|
|
} else if let dose = viewModel.nextDose {
|
|
VStack(alignment: .leading, spacing: 12) {
|
|
Text("PROXIMA TOMA")
|
|
.font(.jakartaBold12)
|
|
.foregroundStyle(.white.opacity(0.75))
|
|
HStack(alignment: .center) {
|
|
Text(dose.time)
|
|
.font(.jakartaBold40)
|
|
Spacer()
|
|
Image(systemName: "pills.fill")
|
|
.font(.system(size: 31))
|
|
}
|
|
Text(dose.title)
|
|
.font(.jakartaBold18)
|
|
Text(dose.detail)
|
|
.font(.jakartaRegular16)
|
|
.foregroundStyle(.white.opacity(0.82))
|
|
}
|
|
.foregroundStyle(.white)
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
.padding(22)
|
|
.background(Color.appBackground)
|
|
.clipShape(RoundedRectangle(cornerRadius: 8))
|
|
} else {
|
|
VStack(spacing: 10) {
|
|
Image(systemName: "checkmark.circle.fill")
|
|
.font(.system(size: 34))
|
|
.foregroundStyle(Color.appBackground)
|
|
Text("Nao tem tomas agendadas.")
|
|
.font(.jakartaRegular16)
|
|
.foregroundStyle(Color.appTextPrimary)
|
|
}
|
|
.frame(maxWidth: .infinity, minHeight: 156)
|
|
.background(.white)
|
|
.clipShape(RoundedRectangle(cornerRadius: 8))
|
|
}
|
|
}
|
|
|
|
private var todaySection: some View {
|
|
VStack(alignment: .leading, spacing: 14) {
|
|
Text("Medicacao de hoje")
|
|
.font(.jakartaBold18)
|
|
.foregroundStyle(Color.appTextPrimary)
|
|
|
|
if viewModel.scheduledDoses.isEmpty && !viewModel.isLoading && viewModel.errorMessage == nil {
|
|
Text("Nao ha medicacao ativa para mostrar.")
|
|
.font(.jakartaRegular16)
|
|
.foregroundStyle(Color.appTextPrimary.opacity(0.65))
|
|
} else {
|
|
ForEach(viewModel.scheduledDoses) { dose in
|
|
HStack(spacing: 16) {
|
|
Text(dose.time)
|
|
.font(.jakartaBold16)
|
|
.foregroundStyle(Color.appBackground)
|
|
.frame(width: 54, alignment: .leading)
|
|
Circle()
|
|
.fill(Color.appBackground.opacity(0.18))
|
|
.frame(width: 40, height: 40)
|
|
.overlay {
|
|
Image(systemName: "pills.fill")
|
|
.foregroundStyle(Color.appBackground)
|
|
}
|
|
VStack(alignment: .leading, spacing: 3) {
|
|
Text(dose.title)
|
|
.font(.jakartaBold16)
|
|
.foregroundStyle(Color.appTextPrimary)
|
|
Text(dose.detail)
|
|
.font(.jakartaRegular14)
|
|
.foregroundStyle(Color.appTextPrimary.opacity(0.62))
|
|
}
|
|
Spacer(minLength: 0)
|
|
}
|
|
.padding(16)
|
|
.background(.white)
|
|
.clipShape(RoundedRectangle(cornerRadius: 8))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
DashboardView()
|
|
}
|
|
// Created by RSA on 28/08/2026.
|
|
//
|
|
|