//
//  MPPositive_HomeFirstCollectionViewCell.swift
//  MusicPlayer
//
//  Created by Mr.Zhou on 2024/4/22.
//

import UIKit
///b面首页展示列表一
class MPPositive_HomeListFirstCollectionViewCell: UICollectionViewCell {
    //封面图
    private lazy var coverImageView:UIImageView = {
        let imageView:UIImageView = .init()
        imageView.contentMode = .scaleAspectFill
        return imageView
    }()
    //标题label
    private lazy var titleLabel:UILabel = createLabel("Title", font: .systemFont(ofSize: 14*width, weight: .semibold), textColor: .white, textAlignment: .left)
    //副标题label
    private lazy var subtitleLabel:UILabel = createLabel("Title", font: .systemFont(ofSize: 11*width, weight: .regular), textColor: .init(hex: "#A3A3A3"), textAlignment: .left)
    //播放状态按钮
    private lazy var statuBtn:UIButton = {
        let btn:UIButton = .init()
        btn.setBackgroundImage(UIImage(named: "Home First'pause"), for: .normal)
        btn.setBackgroundImage(UIImage(named: "Home First'play"), for: .selected)
        btn.isUserInteractionEnabled = false
        return btn
    }()
    var itemViewModel:MPPositive_BrowseItemViewModel!{
        didSet{
            itemViewModel.setUrltoImage(coverImageView)
            titleLabel.text = itemViewModel.title
            subtitleLabel.text = itemViewModel.subtitle
        }
    }
    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
        layer.cornerRadius = 16*width
        addSubview(coverImageView)
        coverImageView.snp.makeConstraints { make in
            make.left.right.top.bottom.equalToSuperview()
        }
        //生成一个黑色半透明View
        let bottomView = setBottomShowView()
        addSubview(bottomView)
        bottomView.snp.makeConstraints { make in
            make.left.right.bottom.equalToSuperview()
            make.height.equalTo(50*width)
        }
    }
    private func setBottomShowView() -> UIView {
        let showView:UIView = .init()
        showView.backgroundColor = .init(hex: "#000000", alpha: 0.7)
        showView.addSubview(statuBtn)
        statuBtn.snp.makeConstraints { make in
            make.width.equalTo(30*width)
            make.height.equalTo(22*width)
            make.centerY.equalToSuperview()
            make.right.equalToSuperview().offset(-14*width).priority(999)
        }
        showView.addSubview(titleLabel)
        titleLabel.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(10*width)
            make.left.equalToSuperview().offset(12*width)
            make.right.equalTo(statuBtn.snp.left).offset(-10*width)
        }
        showView.addSubview(subtitleLabel)
        subtitleLabel.snp.makeConstraints { make in
            make.left.equalTo(titleLabel.snp.left)
            make.top.equalTo(titleLabel.snp.bottom).offset(1*width)
            make.right.equalTo(titleLabel.snp.right)
        }
        return showView
    }
}
