//
//  SongListTopView.swift
//  TSLiveWallpaper
//
//  Created by nkl on 2024/12/23.
//

import Foundation
import UIKit

class SongListTopView: UIView {
    lazy var hStack: UIStackView = {
        let stack: UIStackView = .hStack
        stack.distribution = .fillEqually
        stack.spacing = 16
        return stack
    }()

    lazy var playAllBtn: UIButton = {
        let btn = createButton(title: "Play All".localized(), image: nil, space: 8)
        return btn
    }()

    lazy var shuffleBtn: UIButton = {
        let btn = createButton(title: "Shuffle All".localized(), image: nil, space: 8)
        return btn
    }()

    func createButton(title: String, image: UIImage?, space: CGFloat = 8) -> UIButton {
        let btn = UIButton()
        btn.customCornerRadius = 22
        btn.setTitle(title, for: .normal)
        btn.setTitleColor(.black, for: .normal)
        btn.setImage(image, for: .normal)
        btn.titleLabel?.font = .boldSystemFont(ofSize: 14)
        btn.backgroundColor = .white.withAlphaComponent(0.6)
        // 设置图片和标题的间距
        let spacing: CGFloat = 8 // 间距可以根据需要调整
        btn.imageEdgeInsets = UIEdgeInsets(top: 0, left: -spacing, bottom: 0, right: spacing)
        btn.titleEdgeInsets = UIEdgeInsets(top: 0, left: spacing, bottom: 0, right: -spacing)
        return btn
    }

    override init(frame: CGRect) {
        super.init(frame: frame)

        addChildren()
        makeConstarints()
    }

    func addChildren() {
        addSubview(hStack)

        hStack.addArrangedSubview(playAllBtn)
        hStack.addArrangedSubview(shuffleBtn)
    }

    func makeConstarints() {
        hStack.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }

        playAllBtn.snp.makeConstraints { make in
            make.height.equalTo(44)
        }

        shuffleBtn.snp.makeConstraints { make in
            make.height.equalTo(44)
        }
    }

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