//
//  ImageTextControl.swift
//  TSLiveWallpaper
//
//  Created by nkl on 2024/12/24.
//

import Foundation
import UIKit

class ImageTextControl: UIControl {
    private lazy var imageView: UIImageView = {
        let imageView = UIImageView()
        imageView.contentMode = .scaleAspectFit
        return imageView
    }()

    private lazy var titleLabel: UILabel = {
        let label = UILabel()
        label.textAlignment = .center
        label.font = .systemFont(ofSize: 14)
        label.numberOfLines = 0
        return label
    }()
    
    lazy var vStack : UIStackView = .vStack

    var image: UIImage? {
        didSet {
            imageView.image = image
        }
    }

    var text: String? {
        didSet {
            titleLabel.text = text
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupViews()
    }

    required init?(coder: NSCoder) {
        super.init(coder: coder)
        setupViews()
    }

    private func setupViews() {
        vStack.isUserInteractionEnabled = false
        addSubview(vStack)
        vStack.addArrangedSubview(imageView)
        vStack.addArrangedSubview(titleLabel)

        vStack.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        
        imageView.snp.makeConstraints { make in
            make.width.height.equalTo(24)
        }
    }

    // 配置图片和文字
    func configure(image: UIImage?, text: String?) {
        self.image = image
        self.text = text
    }
}
