//
//  PWNavigationBar.swift
//  PhysicalWallPaper
//
//  Created by nkl on 2024/11/6.
//

import Foundation
import KLExtension

class LWNavigationBar: UIView {
    lazy var titleView: UIImageView = .simpleImage(imageName: "ic_nav_catalog")

    lazy var rightItems: UIStackView = {
        let hStack: UIStackView = .hStack
        hStack.spacing = 24
        return hStack
    }()

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

    func appendItem(item: UIView) {
        rightItems.addArrangedSubview(item)
        item.snp.remakeConstraints { make in
            make.width.height.equalTo(32)
        }
    }

    func addChildren() {
        addSubview(titleView)
        addSubview(rightItems)
    }

    func makeConstraints() {
        titleView.snp.makeConstraints { make in
            make.leading.equalToSuperview().offset(16)
            make.centerY.equalToSuperview()
        }

        rightItems.snp.makeConstraints { make in
            make.trailing.equalToSuperview().offset(-16)
            make.centerY.equalToSuperview()
        }
    }

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

class LWSubNavigationBar: UIView {
    lazy var titleLabel: UILabel = .simpleLabel(text: "", font: .font(name: .PingFangSC, size: 20), color: .white)
    lazy var backButton: UIButton = {
        let btn = UIButton()
        btn.setImage(.naviBackWhite, for: .normal)
        return btn
    }()

    lazy var leftItems: UIStackView = {
        let hStack: UIStackView = .hStack
        hStack.spacing = 24
        return hStack
    }()

    lazy var rightItems: UIStackView = {
        let hStack: UIStackView = .hStack
        hStack.spacing = 24
        return hStack
    }()

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

    func appendRightItem(item: UIView) {
        rightItems.addArrangedSubview(item)
        item.snp.remakeConstraints { make in
            make.width.height.equalTo(32)
        }
    }

    func appendLeftItem(item: UIView) {
        leftItems.addArrangedSubview(item)
        item.snp.remakeConstraints { make in
            make.width.height.equalTo(32)
        }
    }

    func addChildren() {
        addSubview(titleLabel)
        addSubview(leftItems)
        addSubview(rightItems)
        initDefaultItem()
    }

    func initDefaultItem() {
        appendLeftItem(item: backButton)
    }

    func makeConstraints() {
        leftItems.snp.makeConstraints { make in
            make.leading.equalToSuperview().offset(16)
            make.centerY.equalToSuperview()
        }

        titleLabel.snp.makeConstraints { make in
            make.center.equalToSuperview()
        }

        rightItems.snp.makeConstraints { make in
            make.trailing.equalToSuperview().offset(-16)
            make.centerY.equalToSuperview()
        }
    }

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

class LWPlaylistSubNavigationBar: UIView {
    lazy var titleLabel: UILabel = .simpleLabel(text: "", font: .font(name: .PingFangSC, size: 20), color: .white, align: .left)
    lazy var backButton: UIButton = {
        let btn = UIButton()
        btn.setImage(.naviBackWhite, for: .normal)
        return btn
    }()

    lazy var leftItems: UIStackView = {
        let hStack: UIStackView = .hStack
        hStack.spacing = 24
        return hStack
    }()

    lazy var rightItems: UIStackView = {
        let hStack: UIStackView = .hStack
        hStack.spacing = 24
        return hStack
    }()

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

    func appendRightItem(item: UIView) {
        rightItems.addArrangedSubview(item)
        item.snp.remakeConstraints { make in
            make.width.height.equalTo(32)
        }
    }

    func appendLeftItem(item: UIView) {
        leftItems.addArrangedSubview(item)
        item.snp.remakeConstraints { make in
            make.width.height.equalTo(32)
        }
    }

    func addChildren() {
        addSubview(titleLabel)
        addSubview(leftItems)
        addSubview(rightItems)
        initDefaultItem()
    }

    func initDefaultItem() {
        appendLeftItem(item: backButton)
    }

    func makeConstraints() {
        leftItems.snp.makeConstraints { make in
            make.leading.equalToSuperview().offset(16)
            make.centerY.equalToSuperview()
        }

        titleLabel.snp.makeConstraints { make in
            make.leading.equalTo(leftItems.snp.trailing).offset(8)
            make.centerY.equalToSuperview()
            make.leading.equalTo(leftItems.snp.trailing).offset(8)
            make.trailing.equalTo(rightItems.snp.leading).offset(-8)
        }

        rightItems.snp.makeConstraints { make in
            make.trailing.equalToSuperview().offset(-16)
            make.centerY.equalToSuperview()
        }
    }

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

class LWRightNavigationBar: UIView {
    lazy var iconView: UIImageView = .simpleImage(imageName: "ic_nav_music")

    lazy var rightItems: UIStackView = {
        let hStack: UIStackView = .hStack
        hStack.spacing = 24
        return hStack
    }()

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

    func appendRightItem(item: UIView) {
        rightItems.addArrangedSubview(item)
        item.snp.remakeConstraints { make in
            make.width.height.equalTo(32)
        }
    }

    func addChildren() {
        addSubview(iconView)
        addSubview(rightItems)
    }

    func makeConstraints() {
        iconView.snp.makeConstraints { make in
            make.leading.equalToSuperview().offset(16)
            make.centerY.equalToSuperview()
        }

        rightItems.snp.makeConstraints { make in
            make.trailing.equalToSuperview().offset(-16)
            make.centerY.equalToSuperview()
        }
    }

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

class LWManageNavigationBar: UIView {
    lazy var titleLabel: UILabel = .simpleLabel(text: "Select (0/0)", font: .font(name: .PingFangSC, size: 20), color: .black)
    lazy var backButton: UIButton = {
        let btn = UIButton()
        btn.setImage(.naviBackWhite, for: .normal)
        return btn
    }()

    lazy var rightItems: UIStackView = {
        let hStack: UIStackView = .hStack
        hStack.spacing = 24
        return hStack
    }()

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

    func appendRightItem(item: UIView) {
        rightItems.addArrangedSubview(item)
        item.snp.remakeConstraints { make in
            make.width.height.equalTo(36)
        }
    }

    func addChildren() {
        addSubview(titleLabel)
        addSubview(rightItems)
    }

    func makeConstraints() {
        titleLabel.snp.makeConstraints { make in
            make.leading.equalToSuperview().offset(16)
            make.centerY.equalToSuperview()
        }

        rightItems.snp.makeConstraints { make in
            make.trailing.equalToSuperview().offset(-16)
            make.centerY.equalToSuperview()
        }
    }

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