//
//  FS_CollectCollectionCell.swift
//  Funny_sounds
//
//  Created by 忆海16 on 2024/8/27.


import UIKit
import SDWebImage

class FS_CollectCollectionCell: UICollectionViewCell {
    lazy var bgImageV:UIImageView = {
        let bgImageV = UIImageView()
        bgImageV.image = UIImage(named: "collectCellbg")
        bgImageV.contentMode = .scaleToFill
        
        return bgImageV
    }()
    
    lazy var conentImageV:UIImageView = {
        let conentImageV = UIImageView()
        conentImageV.image = UIImage(named: "collectionImageV")
        conentImageV.contentMode = .scaleAspectFit
        conentImageV.layer.cornerRadius = 10
        conentImageV.clipsToBounds = true
        conentImageV.contentMode = .scaleToFill
        return conentImageV
    }()
    
    
    lazy var nameLabel: BorderedLabel = {
        
        let nameLabel = BorderedLabel()
        nameLabel.text = "Air Horn"
        nameLabel.font = UIFont(name: "PaytoneOne-Regular", size: 16)
        nameLabel.textColor = .hexSting(color: "#AFFF6B", alpha: 1) // 设置文本颜色为白色
        nameLabel.numberOfLines = 0
        nameLabel.textAlignment = .center
        return nameLabel
        
    }()
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setUI()
        
        contentView.backgroundColor = .clear
        
    }
    //    MARK: -设置布局
    func setUI(){
        self.addSubview(bgImageV)
        self.addSubview(nameLabel)
        self.addSubview(conentImageV)
        
        
        bgImageV.snp.makeConstraints { make in
            make.top.equalToSuperview()
            make.bottom.equalToSuperview()
            make.right.equalToSuperview()
            make.left.equalToSuperview()
            
        }
        
        nameLabel.snp.makeConstraints { make in
            make.top.equalTo(self.snp.top).offset(7)
            make.centerX.equalToSuperview()
            make.width.equalToSuperview()
            make.height.equalTo(17)
        }
        
        
        conentImageV.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(nameLabel.snp.bottom).offset(13)
            make.height.equalTo(89)
            make.width.equalTo(85)
            
        }
        
    }
    
    var model:AudioFile?{
        didSet{
            if let imageURL = URL(string: model?.preUrl ?? "") {
                conentImageV.sd_setImage(with: imageURL, placeholderImage: UIImage(named: "collectionImageV"))
            }
            nameLabel.text = model?.title
        }
    }
    
    
}



