//
//  MVTagsCell.swift
//  MusicVideoPlus
//
//  Created by ak on 2021/6/4.
//

import BFFramework
import Foundation

class MVTagsCell: UICollectionViewCell {
    // 按钮点击的回调
    var btnClickHandle: ((_ sender: UIButton, _ bgmData: Any?) -> Void)?

    lazy var audioImageView: UIImageView = {
        let audioImageView = UIImageView(image: UIImage(named: "categary_icon"))
        audioImageView.contentMode = .scaleAspectFill
        return audioImageView
    }()
 
 
    lazy var titleLab: UILabel = {
        let titleLab = UILabel()
        titleLab.textAlignment = .left
        titleLab.backgroundColor = .clear
        return titleLab
    }()
 

    @objc class func tagsCell(collectionView: UICollectionView, indexPath: IndexPath) -> MVTagsCell {
        let cell: MVTagsCell = collectionView.dequeueReusableCell(withReuseIdentifier: String(describing: MVTagsCell.self), for: indexPath) as! MVTagsCell
        return cell
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        contentView.addSubview(audioImageView)

        contentView.addSubview(titleLab)
 
    }

    required init?(coder _: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    var bgmData: MVHotVideoModel? {
        didSet {
            addData()
            addLayout()
        }
    }

    func addData() {
        if (bgmData)?.categoryEmoji != nil {
            audioImageView.setNetImage(url: "\((bgmData)?.categoryEmoji ?? "")", placeholder: UIImage(named: "categary_icon")!)
        } else {
            audioImageView.image = UIImage(named: "categary_icon")
        }
        titleLab.text = " \((bgmData)?.categoryName ?? "")"
        if(bgmData?.isSelected ?? false){
            contentView.backgroundColor = UIColor.hexColor(hexadecimal: "#EEF0F3")
            titleLab.textColor = UIColor.hexColor(hexadecimal: "#333333")
            contentView.addCorner(corner: 35 / 2)
            titleLab.font = UIFont.boldSystemFont(ofSize: 15)
        }else{
            contentView.backgroundColor = UIColor.clear
            titleLab.textColor = UIColor.hexColor(hexadecimal: "#9B9B9B")
            titleLab.font = UIFont.systemFont(ofSize: 15)
        }
 
    }

    func addLayout() {
        let margin: CGFloat = 10
 
        audioImageView.snp.remakeConstraints { make in
            make.left.equalToSuperview().offset(8)
            make.centerY.equalToSuperview()
            make.width.height.equalTo(22)
        }
     
        titleLab.snp.remakeConstraints { make in
            make.left.equalTo(audioImageView.snp_right).offset(0)
            make.right.equalToSuperview().offset(-margin)
            make.centerY.equalToSuperview()
        }
    }

   
}
