//
//  CenterTableViewCell.swift
//  MusicPlayer
//
//  Created by Mr.Zhou on 2024/4/2.
//

import UIKit

class CenterTableViewCell: UITableViewCell {
    @IBOutlet weak var coverImageView: UIImageView!
    @IBOutlet weak var titleLabel: UILabel!
    @IBOutlet weak var durationLabel: UILabel!
    var musicView:MusicViewModel!{
        didSet{
            coverImageView.image = musicView.cover
            titleLabel.text = musicView.title
            durationLabel.text = musicView.duration
            //判断当前音乐是否播放中,是不是这首音乐
            guard MPMediaCenterManager.shared.getPlayerState() == .Playing, MPMediaCenterManager.shared.getMusic()?.identifier == musicView.music.identifier else {
                //展示未播放状态
                titleLabel.textColor = .init(hex: "#FFFFFF")
                durationLabel.textColor = .init(hex: "#FFFFFF")
                return
            }
            //展示播放状态
            titleLabel.textColor = .init(hex: "#80F988")
            durationLabel.textColor = .init(hex: "#80F988")
        }
    }
    var moreBlock:((UIButton) -> Void)?
    override func awakeFromNib() {
        super.awakeFromNib()
        selectionStyle = .none
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    //更多操作
    @IBAction func moreClick(_ sender: UIButton) {
        guard moreBlock != nil else {
            return
        }
        moreBlock!(sender)
    }
    
}
