DFStatusOrb.swift 1.98 KB
//
//  DFStatusOrb.swift
//  hippo-watch-extension
//

import SwiftUI

struct DFStatusOrb: View {
    let status: DFStressStatus
    let value: String
    let themeImage: Image?

    init(status: DFStressStatus, value: String, themeImage: Image? = nil) {
        self.status = status
        self.value = value
        self.themeImage = themeImage
    }

    var body: some View {
        ZStack {
            Circle()
                .fill(status.color.opacity(0.16))
            if let themeImage {
                themeImage
                    .resizable()
                    .scaledToFit()
                    .clipShape(Circle())
                    .padding(4)
            }
            Circle()
                .stroke(status.color.opacity(0.34), lineWidth: 5)
            Circle()
                .trim(from: 0.12, to: 0.82)
                .stroke(status.color, style: StrokeStyle(lineWidth: 5, lineCap: .round))
                .rotationEffect(.degrees(110))
            if value.isEmpty {
                if themeImage == nil {
                    Image(systemName: "heart.text.square.fill")
                        .font(.system(size: 12, weight: .semibold))
                        .foregroundStyle(status.color)
                }
            } else if themeImage == nil {
                VStack(spacing: -1) {
                    Text(value)
                        .font(.system(size: 14, weight: .bold, design: .rounded))
                        .foregroundStyle(.white)
                    Text("ms")
                        .font(.system(size: 7, weight: .medium))
                        .foregroundStyle(.white.opacity(0.74))
                }
            } else {
                Text(value)
                    .font(.system(size: 13, weight: .bold, design: .rounded))
                    .foregroundStyle(.white)
                    .padding(.horizontal, 4)
                    .padding(.vertical, 2)
                    .background(Color.black.opacity(0.45), in: Capsule())
            }
        }
    }
}