PulseDetailView.swift 7.48 KB
//
//  PulseDetailView.swift
//  hippo-watch Watch App
//
//  Created by shihao on 2025/10/21.
//

import Foundation
import SwiftUI

struct PulseDetailView: View {
    @StateObject private var userManager = WatchUserinfoManager.share
    @State var pulseType: PulseType
    
    var body: some View {
        ZStack(alignment: .top) {
            LinearGradient(colors: [.init(hex: "#EEE6FF"),
                                    .init(hex: "#ECE3FF"),
                                    .init(hex: "#EEE6FF"),
                                    .init(hex: "#FFFFFF"),
            ],
                           startPoint: .top,
                           endPoint: .bottom)
            .ignoresSafeArea()
            
            Image(.pulseDetailBg)
                .resizable()
                .aspectRatio(contentMode: .fill)
                .frame(width: ScreenSize.width)
                .frame(height: 280.x)
                .ignoresSafeArea()
            
            ScrollView {
                VStack(alignment: .center, spacing: 12) {
                    pulseOverView
                    vipBanner
                    pulseCharacteristicView
                    traditionalChineseMedicineView
                    dietAdviceView
                    sportAdviceView
                    tipView
                    Spacer().frame(height: 40)
                }
            }
            .ignoresSafeArea(.container, edges: .bottom)
        }
    }
    
    @ViewBuilder
    private var pulseOverView: some View {
        VStack(spacing: 0) {
            PulseWaveformView(pulseType: pulseType,
                              lineColor: .white)
            .frame(width: 152.x, height: 85.x, alignment: .center)
            .padding(.top, 34)
            
            Text(pulseType.model.name)
                .wenyiheiFont(size: 24)
                .foregroundColor(.init(hex: "#2C2020"))
                .padding(.top, 14)
            Text(pulseType.model.characteristic)
                .font(.custom("Songti SC Regular", size: 16))
                .foregroundColor(.init(hex: "#896CDC"))
        }
        .padding(.top, 35)
        .padding(.bottom, 20)
    }
    
    @ViewBuilder
    private var vipBanner: some View {
        if isVip == false {
            HStack(spacing: 6) {
                Image(.pulseDetailVipBannerIcon)
                
                Text("前往手机APP开通会员\n即可查看脉象详情")
                    .font(.system(size: 14, weight: .semibold))
                    .foregroundColor(.init(hex: "#FFECBD"))
            }
            .padding(.horizontal, 10)
            .frame(height: 52)
            .background(
                LinearGradient(colors: [.init(hex: "#4B2E78"),
                                        .init(hex: "#794097")], startPoint: .leading, endPoint: .trailing)
            )
            .cornerRadius(12)
            .padding(.bottom, 3)
        }
    }
    
    @ViewBuilder
    private var pulseCharacteristicView: some View {
        HStack {
            VStack(spacing: 4) {
                ForEach(Array(pulseType.model.name), id: \.self) { char in
                    Text(String(char))
                        .font(.custom("Songti SC Bold", size: 16))
                        .foregroundColor(.white)
                }
            }
            .background {
                Image(.pulseDetailTitleBg)
            }
            .padding(.trailing, 12)
            
            VStack(alignment: .leading, spacing: 7) {
                Text("脉象特征")
                    .font(.custom("Songti SC Regular", size: 13))
                    .foregroundColor(.init(hex: "#896CDC"))
                
                Text(pulseType.model.traditionalChineseMedicine.summary)
                    .font(.custom("Songti SC Bold", size: 13))
                    .foregroundColor(.init(hex: "#2C2020"))
                    .blur(radius: isVip ? 0 : 5)
                
            }
        }
        .padding(.horizontal, 17)
        .padding(.bottom, 3)
    }
    
    @ViewBuilder
    private var traditionalChineseMedicineView: some View {
        VStack(alignment: .leading, spacing: 2) {
            HStack(alignment: .center, spacing: 2) {
                Image(.pulseDetailZhongyiIcon)
                Text("中医理论")
                    .wenyiheiFont(size: 12)
                    .foregroundColor(.init(hex: "#2C2020"))
                Spacer()
            }
            
            Text(pulseType.model.traditionalChineseMedicine.bodyShape)
                .font(.custom("Songti SC Bold", size: 13))
                .foregroundColor(.init(hex: "#896CDC"))
                .padding(.leading, 4)
                .blur(radius: isVip ? 0 : 5)
            
            if let mainDisease = pulseType.model.traditionalChineseMedicine.mainDisease {
                Text(mainDisease)
                    .font(.custom("Songti SC Bold", size: 13))
                    .foregroundColor(.init(hex: "#896CDC"))
                    .padding(.leading, 4)
                    .blur(radius: isVip ? 0 : 5)
                    .padding(.bottom, 8)
            }
            
        }
        .padding(.horizontal, 10)
        .padding(.top, 12)
        .padding(.bottom, 20)
        .background(.white)
        .cornerRadius(24)
        .padding(.horizontal, 18)
    }
    
    @ViewBuilder
    private var dietAdviceView: some View {
        VStack(alignment: .leading, spacing: 2) {
            HStack(alignment: .center, spacing: 2) {
                Image(.pulseDetailDietIcon)
                Text("饮食建议")
                    .wenyiheiFont(size: 12)
                    .foregroundColor(.init(hex: "#2C2020"))
                Spacer()
            }
            
            Text(pulseType.model.dietAdvice)
                .font(.custom("Songti SC Bold", size: 13))
                .foregroundColor(.init(hex: "#896CDC"))
                .padding(.leading, 4)
                .blur(radius: isVip ? 0 : 5)
        }
        .padding(.horizontal, 10)
        .padding(.top, 12)
        .padding(.bottom, 17)
        .background(.white)
        .cornerRadius(24)
        .padding(.horizontal, 18)
    }
    
    @ViewBuilder
    private var sportAdviceView: some View {
        VStack(alignment: .leading, spacing: 2) {
            HStack(alignment: .center, spacing: 2) {
                Image(.pulseDetailSportIcon)
                    
                Text("运动建议")
                    .wenyiheiFont(size: 12)
                    .foregroundColor(.init(hex: "#2C2020"))
                
                Spacer()
            }
            
            Text(pulseType.model.sportAdvice)
                .font(.custom("Songti SC Bold", size: 13))
                .foregroundColor(.init(hex: "#896CDC"))
                .padding(.leading, 4)
                .blur(radius: isVip ? 0 : 5)
            
        }
        .padding(.horizontal, 10)
        .padding(.top, 12)
        .padding(.bottom, 18)
        .background(.white)
        .cornerRadius(24)
        .padding(.horizontal, 18)
    }
    
    @ViewBuilder
    private var tipView: some View {
        Text(
             """
特别提醒
本结论中提供的建议仅供参考
如您有任何健康疑虑或不适症状
请及时咨询正规医疗机构或执业医师
"""
        )
        .font(.custom("Songti SC Regular", size: 9))
        .foregroundColor(.init(hex: "#908B91"))
        .multilineTextAlignment(.center)
        .lineSpacing(6)
        .padding(.top, 17)
        .padding(.bottom, 24)
    }
    
    private var isVip: Bool {
        return userManager.isMeVip ?? false
    }
}