//
//  HeartBeatView.swift

//
//  Created by Leon on 2025/8/14.
//

import UIKit

enum HeartBeatSize {
    case small
    case medium
}

/// 小爱心❤️ + 37.8温度
class HeartBeatView: UIView{
    var icon: UIImageView!
    var value: UILabel!
    
    var viewSize: HeartBeatSize = .small
    
    var content: String = "-"{
        didSet{
            if content.count > 0{
                value.text = "\(content)℃"
            }else{
                value.text = "-"
            }
        }
    }

    init(viewSize: HeartBeatSize) {
        self.viewSize = viewSize
        super.init(frame: .zero)
        setupViews()
        setupData()
        setupEvent()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    private func setupViews() {
        icon = {
            let v = UIImageView()
            v.image = UIImage(named: "heartbeat")
            addSubview(v)
            v.snp.makeConstraints { make in
                make.leading.equalToSuperview()
                make.centerY.equalToSuperview()
            }
            return v
        }()

        value = {
            let v = UILabel()
            v.textColor = .text
            v.setContentCompressionResistancePriority(UILayoutPriority(756), for: .horizontal)
            addSubview(v)
            v.snp.makeConstraints { make in
                make.leading.equalTo(icon.snp.trailing).offset(4)
                make.top.equalToSuperview()
                make.bottom.equalToSuperview()
                make.trailing.equalToSuperview()
            }
            return v
        }()
        value.text = "-"
    }

    private func setupData() {
        switch viewSize {
        case .small:
            icon.snp.makeConstraints { make in
                make.size.equalTo(CGSize(width: 12, height: 12))
            }
            value.font = .t.tls
        case .medium:
            icon.snp.makeConstraints { make in
                make.size.equalTo(CGSize(width: 20, height: 20))
            }
            value.font = .t.tlm
        }
    }

    private func setupEvent() {
    }
}
