//
//  TickButton.swift

//
//  Created by Leon on 2025/7/19.
//

import UIKit
import SnapKit

class TickButton: CLButton {
    // MARK: - Properties
    private var normalTintColor: UIColor
    private var disableTintColor: UIColor
    
    // MARK: - Initialization
    override init(frame: CGRect) {
        normalTintColor = .c.ctpn
        disableTintColor = .c.ctpd
        
        super.init(frame: frame)
        tickmark()
    }
    
    @available(*, unavailable)
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - Setup
    func tickmark() {
        layer.cornerRadius = 16
        clipsToBounds = true
        
        let tick = MWIconFont.image(fromIcon: .select, size:  CGSize(width: 16, height: 16), color: .c.ctpn)
        setImage(tick, for: .normal)
        setBackgroundImage(UIImage.withColor(color: .c.cpn, size: CGSize(width: 10, height: 10)), for: .normal)
        setBackgroundImage(UIImage.withColor(color: .c.cpd, size: CGSize(width: 10, height: 10)), for: .disabled)
        setBackgroundImage(UIImage.withColor(color: .c.cpp, size: CGSize(width: 10, height: 10)), for: .highlighted)
        
        snp.makeConstraints { make in
            make.height.equalTo(32)
            make.width.equalTo(52)
        }
    }
    
    override var isEnabled: Bool {
        didSet {
            tintColor = isEnabled ? normalTintColor : disableTintColor
        }
    }
}
