HistoryView.swift 2.05 KB
//
//  HistoryView.swift
//  browser
//
//  Created by Artem Talko on 29.09.2023.
//
//MARK: Checked
import UIKit

final class HistoryView: UIView {
    let historySearchBar: HistorySearchBarView = {
        let obj = HistorySearchBarView()
        obj.layer.cornerRadius = 10
        obj.backgroundColor = UIColor(red: 0.913, green: 0.913, blue: 0.947, alpha: 1)
        return obj
    }()
    
    let historyTabsTableView: UITableView = {
        let obj = UITableView()
        obj.separatorStyle = .none
        return obj
    }()
    
    let historyToolbarView: HistoryToolbarView = {
        let obj = HistoryToolbarView()
        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 = .gray.withAlphaComponent(0.1)
        
        addSubview(historySearchBar)
        addSubview(historyTabsTableView)
        addSubview(historyToolbarView)
        setupConstraints()
    }
    
    private func setupConstraints() {
        historySearchBar.snp.makeConstraints { make in
            make.top.equalTo(safeAreaLayoutGuide.snp.top).offset(16.sizeH)
            make.leading.trailing.equalToSuperview().inset(16.sizeW)
        }
       
        historyTabsTableView.snp.makeConstraints { make in
            make.top.equalTo(historySearchBar.snp.bottom).offset(32.sizeH)
            make.leading.trailing.equalToSuperview().inset(16.sizeW)
            make.bottom.equalTo(historyToolbarView.snp.top).inset(7.sizeH)
            make.height.equalTo(600.sizeH)
        }
        
        historyToolbarView.snp.makeConstraints { make in
            make.leading.trailing.equalToSuperview()
            make.bottom.equalTo(safeAreaLayoutGuide.snp.bottom)
        }
    }
}

//MARK: - Helpers
extension HistoryView: UITextFieldDelegate {
    func textFieldDidBeginEditing(_ textField: UITextField) {
        historySearchBar.searchTextFieldView.text = ""
    }
}