//
//  MusicEmptyView.swift
//  PhysicalWallPaper
//
//  Created by nkl on 2024/11/13.
//

import Foundation
import UIKit

class CWTopCustomButton: UIControl {
    lazy var iconView: UIImageView = .init(image: UIImage(named: "icon_mine_favourite"))
    lazy var titleLabel: UILabel = .simpleLabel(text: "Like".localized(), font: .systemFont16, color: .white.withAlphaComponent(0.8))
    lazy var countLabel: UILabel = .simpleLabel(text: "0", font: .systemFont14, color: .white.withAlphaComponent(0.4))

    init(iconName: String, title: String) {
        super.init(frame: .zero)
        backgroundColor = .white.withAlphaComponent(0.1)
        layer.cornerRadius = 16
        iconView.image = UIImage(named: iconName)
        iconView.clipsToBounds = true
        titleLabel.text = title
        addChildren()
        makeConstraints()
    }

    func addChildren() {
        addSubview(iconView)
        addSubview(titleLabel)
        addSubview(countLabel)
    }

    func makeConstraints() {
        iconView.snp.makeConstraints { make in
            make.leading.equalToSuperview().offset(12)
            make.centerY.equalToSuperview()
            make.width.height.equalTo(60)
        }

        titleLabel.snp.makeConstraints { make in
            make.top.equalTo(iconView.snp.top).offset(5)
            make.leading.equalTo(iconView.snp.trailing).offset(12)
            make.trailing.equalToSuperview().offset(-12)
        }

        countLabel.snp.makeConstraints { make in
            make.bottom.equalTo(iconView.snp.bottom).offset(-5)
            make.leading.equalTo(iconView.snp.trailing).offset(12)
            make.trailing.equalToSuperview().offset(-12)
        }
    }

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