82 lines
3.3 KiB
Swift
82 lines
3.3 KiB
Swift
//
|
||
// SplitPickerView.swift
|
||
// Workouts
|
||
//
|
||
// Created by rzen on 7/13/25 at 7:17 PM.
|
||
//
|
||
// Copyright 2025 Rouslan Zenetl. All Rights Reserved.
|
||
//
|
||
|
||
import SwiftUI
|
||
import SwiftData
|
||
|
||
struct SplitPickerView: View {
|
||
@Environment(\.modelContext) private var modelContext
|
||
@Environment(\.dismiss) private var dismiss
|
||
|
||
@Query(sort: [SortDescriptor(\Split.name)]) private var splits: [Split]
|
||
|
||
var onSplitSelected: (Split) -> Void
|
||
|
||
var body: some View {
|
||
NavigationStack {
|
||
ScrollView {
|
||
LazyVGrid(columns: [GridItem(.flexible()), GridItem(.flexible())], spacing: 16) {
|
||
ForEach(splits) { split in
|
||
Button(action: {
|
||
onSplitSelected(split)
|
||
dismiss()
|
||
}) {
|
||
VStack {
|
||
ZStack(alignment: .bottom) {
|
||
// Golden ratio rectangle (1:1.618)
|
||
RoundedRectangle(cornerRadius: 12)
|
||
.fill(
|
||
LinearGradient(
|
||
gradient: Gradient(colors: [split.getColor(), split.getColor().darker(by: 0.2)]),
|
||
startPoint: .topLeading,
|
||
endPoint: .bottomTrailing
|
||
)
|
||
)
|
||
.aspectRatio(1.618, contentMode: .fit)
|
||
.shadow(radius: 2)
|
||
|
||
VStack {
|
||
// Icon in the center
|
||
Image(systemName: split.systemImage)
|
||
.font(.system(size: 40, weight: .medium))
|
||
.foregroundColor(.white)
|
||
.offset(y: -15)
|
||
|
||
// Name at the bottom inside the rectangle
|
||
Text(split.name)
|
||
.font(.headline)
|
||
.foregroundColor(.white)
|
||
.lineLimit(1)
|
||
.padding(.horizontal, 8)
|
||
.padding(.bottom, 8)
|
||
}
|
||
}
|
||
|
||
// Exercise count below the rectangle
|
||
Text("\(split.exercises?.count ?? 0) exercises")
|
||
.font(.caption)
|
||
.foregroundColor(.secondary)
|
||
}
|
||
}
|
||
.buttonStyle(PlainButtonStyle())
|
||
}
|
||
}
|
||
.padding()
|
||
}
|
||
.toolbar {
|
||
ToolbarItem(placement: .navigationBarLeading) {
|
||
Button("Cancel") {
|
||
dismiss()
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|