HistoryView.swift 2.01 KB
//
//  HistoryView.swift
//  browser
//
//  Created by Artem Talko on 29.09.2023.
//

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)
        setup()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setup() {
        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.bottom.equalTo(historyToolbarView.snp.top).inset(7.sizeH)
            make.leading.trailing.equalToSuperview().inset(16.sizeW)
            make.height.equalTo(600.sizeH)
        }
        historyToolbarView.snp.makeConstraints { make in
            make.bottom.equalTo(safeAreaLayoutGuide.snp.bottom)
            make.leading.trailing.equalToSuperview()
        }
    }
}

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