//
//  MVProductEmptyView.swift
//  MusicVideoPlus
//
//  Created by SanW on 2021/6/23.
//


import UIKit

class MVProductEmptyView: UIView {
    var btnClickHandle: ((_ sender: UIButton) -> Void)?
    lazy var reCreateBtn: UIButton = {
        let reCreateBtn = UIButton(type: .custom)
        reCreateBtn.setTitle("制作卡点视频", for: .normal)
        reCreateBtn.titleLabel?.font = UIFont.systemFont(ofSize: 18, weight: .semibold)
        reCreateBtn.setTitleColor(UIColor.white, for: .normal)
        reCreateBtn.addCorner(corner: 8)
        reCreateBtn.tag = 1
        reCreateBtn.addTarget(self, action: #selector(btnClick(sender:)), for: .touchUpInside)
        reCreateBtn.backgroundColor = UIColor(red: 61.0 / 255.0, green: 193.0 / 255.0, blue: 193.0 / 255.0, alpha: 0.8)
        return reCreateBtn
    }()

    let emptyImageView: UIImageView = {
        let emptyImageView = UIImageView(image: UIImage(named: "empty_mine_product"))
        return emptyImageView
    }()

    lazy var titleLabel: UILabel = {
        let titleLabel = UILabel()
        titleLabel.textColor = UIColor.hexColor(hexadecimal: "#E0E0E0")
        titleLabel.text = "暂无作品"
        titleLabel.numberOfLines = 1
        titleLabel.textAlignment = .center
        titleLabel.font = UIFont.systemFont(ofSize: 18, weight: .semibold)
        return titleLabel
    }()

    override init(frame: CGRect) {
        super.init(frame: frame)
        addSubview(emptyImageView)
        addSubview(titleLabel)
        addSubview(reCreateBtn)
    }

    required init?(coder _: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override func layoutSubviews() {
        super.layoutSubviews()
        let margin: CGFloat = cDefaultMargin * 2
        let btnH: CGFloat = cDefaultMargin * 5
        reCreateBtn.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(margin)
            make.right.equalToSuperview().offset(-margin)
            make.bottom.equalToSuperview().offset(-(btnH + cSafeAreaHeight))
            make.height.equalTo(btnH)
        }
        emptyImageView.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.centerY.equalToSuperview().offset(-btnH * 2)
            make.width.equalTo(margin * 5)
            make.height.equalTo(margin * 3)
        }
        titleLabel.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.top.equalTo(emptyImageView.snp.bottom).offset(cDefaultMargin)
        }
    }

    @objc func btnClick(sender: UIButton) {
        if btnClickHandle != nil {
            btnClickHandle!(sender)
        }
    }
}
