//
//  VoiceSelectView.swift

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

/// 大块block，竖着排列：语言图标 + 文字
class VoiceSelectView:UIView{

    var iv: CLImageView!
    var titleLabel: UILabel!
    var topButton: UIButton!

    var topTapBlock: (() -> Void)?
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupViews()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupViews(){
        backgroundColor = .c.csen
        layer.cornerRadius = 16
        clipsToBounds = true

        iv = {
            let v = CLImageView(frame: .zero)
            v.image = MWIconFont.image(fromIcon: .voice, size:  CGSize(width: 24, height: 24), color: .c.ctsn)
            addSubview(v)
            v.snp.makeConstraints { make in
                make.centerX.equalToSuperview()
                make.top.equalToSuperview().offset(24)
                make.size.equalTo(CGSize(width: 24, height: 24))
            }
            return v
        }()

        titleLabel = {
            let v = UILabel()
            v.font = .t.tbm
            v.textColor = .c.ctsn
            addSubview(v)
            v.snp.makeConstraints { make in
                make.centerX.equalToSuperview()
                make.top.equalTo(iv.snp.bottom).offset(16)
                make.bottom.equalToSuperview().offset(-24)
            }
            return v
        }()

        titleLabel.text = "Select 1 voice from below"

        topButton = {
            let v = UIButton()
            addSubview(v)
            v.snp.makeConstraints { make in
                make.edges.equalToSuperview()
            }
            v.addTarget(self, action: #selector(topButtonTap), for: .touchUpInside)
            return v
        }()
    }

    @objc private func topButtonTap(){
        topTapBlock?()
    }
}
