//
//  PlayerActionView.swift
//  MusicPlayer
//
//  Created by Mr.Zhou on 2024/4/10.
//

import UIKit
///播放器各事项View
class PlayerActionView: UIView {
    //常规图片（展示dark和light状态的图片）
    private lazy var normalImageView:UIImageView = {
        let imageView:UIImageView = .init()
        imageView.contentMode = .scaleAspectFill
        return imageView
    }()
    //运行时图片（当功能运行时图片，视图最上层）
    private lazy var playingImageView:UIImageView = {
        let imageView:UIImageView = .init()
        imageView.contentMode = .scaleAspectFill
        return imageView
    }()
    //dark状态下图片
    var darkImage:UIImage!
    //light状态下图片
    var lightImage:UIImage!
    //playing状态下图片
    var playingImage:UIImage!
    //是dark还是light？
    var isDark:Bool = true{
        didSet{
            normalImageView.image = isDark ? darkImage:lightImage
        }
    }
    //是否运行时
    var isPlaying:Bool = false{
        didSet{
            playingImageView.image = playingImage
            normalImageView.isHidden = isPlaying
            playingImageView.isHidden = !isPlaying
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        setUpLayout()
    }
    override func awakeFromNib() {
        super.awakeFromNib()
        setUpLayout()
    }
    required init?(coder: NSCoder) {
        super.init(coder: coder)
//        setUpLayout()
    }
    override func layoutSubviews() {
        super.layoutSubviews()
        //xib加载完成后，设置圆角
        layer.masksToBounds = true
        layer.cornerRadius = frame.size.width/2
    }
    
    //约束加载
    private func setUpLayout() {
        isUserInteractionEnabled = true
        addSubview(normalImageView)
        normalImageView.snp.makeConstraints { make in
            make.center.equalToSuperview()
            make.width.height.equalTo(26*width)
        }
        normalImageView.isHidden = false
        addSubview(playingImageView)
        playingImageView.snp.makeConstraints { make in
            make.center.equalToSuperview()
            make.width.height.equalTo(26*width)
        }
        playingImageView.isHidden = true
    }
    
}
