//
//  AlbumButton.swift
//  wyy
//
//  Created by 施书顺 on 2021/3/5.
//

import UIKit
import SnapKit

class AlbumButton: UIButton {
    
    let spacing : CGFloat = 5.0
    let label = UILabel()
    var count : Int = 0
    let countLabel = UILabel()
    
    init(imageName: String, title: String, count: Int){
        super.init(frame: CGRect.zero)
        self.count = count
        snp.makeConstraints{ make in
            make.width.equalTo(100)
            make.height.equalTo(100)
        }
        setImage(UIImage(named: imageName), for: .normal)
        imageView?.layer.cornerRadius = 10
        
        addSubview(label)
        label.text = title
        label.font = UIFont.systemFont(ofSize: 13)
        label.numberOfLines = 2
        label.lineBreakMode = .byWordWrapping
        label.textAlignment = .left
        label.snp.makeConstraints{ make in
            make.top.equalTo(105)
            make.left.equalTo(5)
            make.width.equalTo(100)
        }
        
        countLabel.text = "▷ \(count)"
        countLabel.font = UIFont.systemFont(ofSize: 12)
        countLabel.textColor = UIColor.white
        countLabel.textAlignment = .right
        addSubview(countLabel)
        countLabel.snp.makeConstraints{ make in
            make.top.equalTo(3)
            make.right.equalToSuperview().offset(-8)
        }
        let blurEffect = UIBlurEffect(style: .light)
        let blurEffectView = UIVisualEffectView(effect: blurEffect)
        blurEffectView.layer.cornerRadius = 6
        blurEffectView.clipsToBounds = true
        addSubview(blurEffectView)
        blurEffectView.snp.makeConstraints{ make in
            make.top.equalTo(3)
            make.right.equalToSuperview().offset(-5)
            make.width.equalTo(countLabel.snp.width).offset(6)
            make.height.equalTo(countLabel.snp.height).offset(2)
        }
        bringSubviewToFront(countLabel)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
