//
//  SongListBottomView.swift
//  TSLiveWallpaper
//
//  Created by nkl on 2024/12/24.
//

import Foundation
import UIKit

class SongListBottomView: UIView {
    lazy var deleteView: ImageTextControl = {
        let delete = ImageTextControl()
        delete.configure(image: .icDelete, text: "Delete".localized())
        return delete
    }()

    lazy var addToPlaylist: ImageTextControl = {
        let delete = ImageTextControl()
        delete.configure(image: .icAddPlaylist, text: "Add to Playlist".localized())
        return delete
    }()

    lazy var removeFromPlaylist: ImageTextControl = {
        let delete = ImageTextControl()
        delete.configure(image: .icRemovePlaylist, text: "Remove from playlist".localized())
        return delete
    }()

    lazy var hStack: UIStackView = {
        let stk = UIStackView.hStack
        stk.distribution = .fillEqually
        return stk
    }()

    override init(frame: CGRect) {
        super.init(frame: frame)
        addChildren()
        makeConstraints()
    }

    var isPlaylist: Bool = false {
        didSet {
            removeFromPlaylist.isHidden = !isPlaylist
            addToPlaylist.isHidden = isPlaylist
        }
    }

    func addChildren() {
        backgroundColor = .white
        addSubview(hStack)
        hStack.addArrangedSubview(removeFromPlaylist)
        hStack.addArrangedSubview(addToPlaylist)
        hStack.addArrangedSubview(deleteView)

        removeFromPlaylist.isHidden = !isPlaylist
        addToPlaylist.isHidden = isPlaylist
    }

    func makeConstraints() {
        hStack.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(12)
            make.leading.trailing.equalToSuperview()
            make.bottom.equalTo(safeAreaLayoutGuide.snp.bottom)
        }
    }

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