HistoryToolbarView.swift 1.27 KB
//
//  ToolbarView.swift
//  browser
//
//  Created by Artem Talko on 29.09.2023.
//

import UIKit

enum historyToolbarElementType {
    case clean
}

final class HistoryToolbarView: UIView  {
    var action: ((historyToolbarElementType) -> Void)?
    
    private let cleanHistoryButton: UIButton = {
        let obj = UIButton()
        obj.setTitle("Clean", for: .normal)
        obj.setTitleColor(.systemBlue, for: .normal)
        let menuItems: [UIMenuElement] = menuCases.allCases.map { $0.action }
        obj.menu = UIMenu(title: StringConstants.menuTitle, children: menuItems)
        obj.showsMenuAsPrimaryAction = true
        
        return obj
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI() {
        backgroundColor = .white
        
        addSubview(cleanHistoryButton)
        setupConstraints()
    }
    
    private func setupConstraints() {
        cleanHistoryButton.snp.makeConstraints { make in
            make.top.bottom.equalToSuperview()
            make.trailing.equalToSuperview().inset(20.sizeW)
            make.height.equalTo(20.sizeH)
        }
    }
}