//
//  SpeakProgressStudySecCell.swift
//  SpeakEasyLearnEnglish
//
//  Created by edy on 2025/7/22.
//

import UIKit

class SpeakProgressStudySecCell: UICollectionViewCell {

    static let id = "SpeakProgressStudySecCell"
    
    @BoundedDoubleNumber var progress:Double = 1
    
    // MARK: - ib
    @IBOutlet weak var SpeakMaxLabel: UILabel!
    @IBOutlet weak var SpeakProgressView: UIView!
    @IBOutlet weak var SpeakStudyTm: UILabel!
    
    var color:UIColor = .clear {
        didSet {
            SpeakMaxLabel.textColor = color
            ProgressLayer.backgroundColor = color.cgColor
        }
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        DispatchQueue.main.async {
            self.layoutIfNeeded()
            self.setProgress()
        }
    }

    func setProgress() -> Void {
        let height = self.SpeakProgressView.height
        let frame = CGRect(x: 0, y: height * (1.0-progress) , width: self.SpeakProgressView.width, height: height * progress)
        self.ProgressLayer.frame = frame
        self.ProgressLayer.cornerRadius = self.SpeakProgressView.width / 2.0
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        self.layoutIfNeeded()
        self.setProgress()
    }
    
    private lazy var ProgressLayer: CALayer = {
        let l = CALayer()
        SpeakProgressView.layer.addSublayer(l)
        return l
    }()
}
