//
//  MPPositive_HomeLibraryListCollectionViewCell.swift
//  relax.offline.mp3.music
//
//  Created by Mr.Zhou on 2024/7/24.
//

import UIKit
import Kingfisher
class MPPositive_HomeLibraryListCollectionViewCell: UICollectionViewCell {
    //封面
    private lazy var coverImageView:UIImageView = {
        let imageView:UIImageView = .init()
        imageView.contentMode = .scaleAspectFill
        imageView.layer.masksToBounds = true
        imageView.layer.cornerRadius = 16*width
        return imageView
    }()
    private lazy var iconImageView:UIImageView = {
        let iconImageView:UIImageView = .init()
        iconImageView.contentMode = .scaleAspectFill
        return iconImageView
    }()
    //标题Label
    private lazy var titleLabel:UILabel = createLabel("Title", font: .systemFont(ofSize: 14*width, weight: .regular), textColor: .white, textAlignment: .left)
    var library:MPPositive_LibraryViewModel!{
        didSet{
            coverImageView.kf.setImage(with: library.cover, placeholder: library.library.libraryType.image)
            titleLabel.text = library.title
            if let icon = library.library.libraryType.icon {
                iconImageView.image = icon
            }else {
                iconImageView.image = nil
            }
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        confirgue()
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }
    //配置
    private func confirgue() {
        backgroundColor = .clear
        layer.masksToBounds = true
        addSubview(coverImageView)
        coverImageView.snp.makeConstraints { make in
            make.left.top.right.equalToSuperview()
            make.height.equalTo(109*width)
        }
        addSubview(iconImageView)
        iconImageView.snp.makeConstraints { make in
            make.width.height.equalTo(20*width)
            make.left.equalToSuperview().offset(8*width)
            make.top.equalToSuperview().offset(13*width)
        }
        addSubview(titleLabel)
        titleLabel.snp.makeConstraints { make in
            make.top.equalTo(coverImageView.snp.bottom).offset(9*width)
            make.left.right.equalToSuperview()
        }
    }
}
