//
//  FS_ClassificationCollectionCell.swift
//  Funny_sounds
//
//  Created by 忆海16 on 2024/8/15.
//

import UIKit
import SDWebImage

class FS_ClassificationCollectionCell: UICollectionViewCell {
    
    lazy var bgImageV:UIImageView = {
        let bgImageV = UIImageView()
        bgImageV.image = UIImage(named: "classbg")
        bgImageV.contentMode = .scaleToFill
        
        return bgImageV
    }()
    
    lazy var conentImageV:UIImageView = {
        let conentImageV = UIImageView()
        conentImageV.image = UIImage(named: "collectionImageV")
        conentImageV.contentMode = .scaleAspectFit
        conentImageV.layer.cornerRadius = 40
        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 = .white // 设置文本颜色为白色
        nameLabel.numberOfLines = 0
        nameLabel.textAlignment = .center
        
        // 设置阴影效果
        let shadow = NSShadow()
        shadow.shadowColor = UIColor.black.withAlphaComponent(1.0) // 黑色阴影
        shadow.shadowOffset = CGSize(width: 0, height: 6) // 向下偏移2个点
        shadow.shadowBlurRadius = 0 // 无模糊度
        
        // 设置属性字符串并应用阴影
        let attributedText = NSMutableAttributedString(string: nameLabel.text!)
        attributedText.addAttribute(.shadow, value: shadow, range: NSRange(location: 0, length: nameLabel.text!.count))
        nameLabel.attributedText = attributedText
        
        nameLabel.sizeToFit()
        
        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(conentImageV)
        self.addSubview(nameLabel)
        
        bgImageV.snp.makeConstraints { make in
            make.width.height.equalTo(100)
            make.top.equalToSuperview().offset(5)
            make.centerX.equalToSuperview()
        }
        
        conentImageV.snp.makeConstraints { make in
            make.centerX.centerY.equalTo(bgImageV)
            make.height.width.equalTo(80)
        }
        
        nameLabel.snp.makeConstraints { make in
            make.top.equalTo(conentImageV.snp.bottom).offset(8)
            make.width.equalToSuperview()
        }
        
    }
    
    var model:AudioFile?{
        didSet{
            if let imageURL = URL(string: model?.preUrl ?? "") {
//                wpImagV.sd_setImage(with: imageURL, completed: nil)
                conentImageV.sd_setImage(with: imageURL, placeholderImage: UIImage(named: "collectionImageV"))
                }
            nameLabel.text = model?.title
        }
    }
    
}
