//
//  CWOperateButton.swift
//  ColorfulWallpaper
//
//  Created by nkl on 2024/9/23.
//

import Foundation
import UIKit

class CWOperateButton : UIControl {
    
    lazy var bgView : UIView = .simpleView(color: .white.withAlphaComponent(0.1))
    
    lazy var iconView : UIImageView = .simpleImage(imageName: "icon_delete")
    
    lazy var titleLabel : UILabel = .simpleLabel(text: "Delete".localized(),font: .systemFont12,color: .white)
    
    
    init(title:String,imgName:String) {
        super.init(frame: .zero)
        self.iconView.image = UIImage.init(named: imgName)
        self.titleLabel.text = title
        self.titleLabel.textAlignment = .center
        bgView.isUserInteractionEnabled = false
        addChildren()
        makeConstraints()
    }
    
    func addChildren(){
        bgView.customCornerRadius = 16
        addSubview(bgView)
        bgView.addSubview(iconView)
        addSubview(titleLabel)
    }
    
    func makeConstraints(){
        bgView.snp.makeConstraints { make in
            make.top.equalToSuperview()
            make.centerX.equalToSuperview()
            make.height.width.equalTo(48)
        }
        
        iconView.snp.makeConstraints { make in
            make.center.equalTo(bgView)
        }
        
        titleLabel.snp.makeConstraints { make in
            make.leading.trailing.equalToSuperview()
            make.width.greaterThanOrEqualTo(48)
            make.bottom.equalToSuperview()
            make.top.equalTo(bgView.snp.bottom).offset(8)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
