//
//  ManageMenuAlertView.swift
//  TSLiveWallpaper
//
//  Created by nkl on 2025/1/7.
//

import Foundation

class ManageMenuAlertView: UIControl {
    lazy var sortButton: UIButton = {
        let btn = UIButton()
        btn.setTitle("Sort By", for: .normal)
        btn.setTitleColor(.black, for: .normal)
        btn.setImage(.icNavSort, for: .normal)
        // 调整图片和标题的间距
        btn.imageEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 5) // 右侧添加间距
        btn.titleEdgeInsets = UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 0) // 左侧添加间距
        return btn
    }()

    lazy var manageButton: UIButton = {
        let btn = UIButton()
        btn.setTitle("Manage", for: .normal)
        btn.setTitleColor(.black, for: .normal)
        btn.setImage(.icNavManage, for: .normal)
        // 调整图片和标题的间距
        btn.imageEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 5) // 右侧添加间距
        btn.titleEdgeInsets = UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 0) // 左侧添加间距
        return btn
    }()

    lazy var bgView: UIView = .simpleView(color: .white)

    lazy var vStack: UIStackView = .vStack

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

    func addChildren() {
        bgView.customCornerRadius = 20
        addSubview(bgView)
        bgView.addSubview(vStack)
        vStack.addArrangedSubview(sortButton)
        vStack.addArrangedSubview(manageButton)
    }

    func makeConstraints() {
        bgView.snp.makeConstraints { make in
            make.trailing.equalToSuperview().offset(-16)
            make.top.equalToSuperview().offset(100)
        }

        vStack.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }

        sortButton.snp.makeConstraints { make in
            make.width.equalTo(125)
            make.height.equalTo(48)
        }

        manageButton.snp.makeConstraints { make in
            make.width.equalTo(125)
            make.height.equalTo(48)
        }
    }

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