//
//  MPBottomShowView.swift
//  MusicPlayer
//
//  Created by Mr.Zhou on 2024/4/8.
//

import UIKit
///底部当前播放音乐展示View（播放器音乐存在时显现）
class MPBottomShowView: UIView, instanceFromNibDelegate {
    @IBOutlet weak var backImageView: UIImageView!{
        didSet{
            backImageView.isUserInteractionEnabled = true
            backImageView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(pushPlayerActionClick(_ :))))
        }
    }
    @IBOutlet weak var coverImageView: UIImageView!
    @IBOutlet weak var titleLabel: UILabel!
    @IBOutlet weak var subtitleLabel: UILabel!
    //播放器状态
    @IBOutlet weak var stateBtn: UIButton!
    //倒计时按钮（常态显示，倒计时隐藏）
    @IBOutlet weak var timerBtn: UIButton!
    //倒计时View（常态隐藏，倒计时显示）
    @IBOutlet weak var timerView: UIView!{
        didSet{
            timerView.layer.masksToBounds = false
            timerView.isUserInteractionEnabled = true
            timerView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(timerActionClick(_ :))))
        }
    }
    //倒计时Label（常态隐藏，倒计时显示）
    @IBOutlet weak var timerLabel: UILabel!
    //弹出计时器闭包
    var modalTimerBlock:ActionBlock?
    //前往播放器页面闭包
    var pushPlayerBlock:ActionBlock?
    //切换播放器状态包
    var switchPlayerBlock:ActionBlock?
    override func awakeFromNib() {
        super.awakeFromNib()
        
    }
    //MARK: - 交互事件
    //弹出计时器
    @IBAction func timerClick(_ sender: UIButton) {
        guard modalTimerBlock != nil else {
            return
        }
        modalTimerBlock!()
    }
    //启动播放/暂停播放
    @IBAction func switchStateClick(_ sender: UIButton) {
        guard switchPlayerBlock != nil else {
            return
        }
        switchPlayerBlock!()
    }
    //弹出计时选择器
    @objc private func timerActionClick(_ sender:UITapGestureRecognizer) {
        guard modalTimerBlock != nil else {
            return
        }
        modalTimerBlock!()
    }
    //前往播放器页面
    @objc private func pushPlayerActionClick(_ sender:UITapGestureRecognizer) {
        guard pushPlayerBlock != nil else {
            return
        }
        pushPlayerBlock!()
    }
}
