SearchingTableViewCell.swift 2.53 KB
//
//  SearchingTableViewCell.swift
//  browser
//
//  Created by Artem Talko on 29.09.2023.
//

import UIKit

final class SearchingTableViewCell: UITableViewCell {
    static let cellID = String(describing: SearchingTableViewCell.self)
    
    var model: String? {
        didSet {
            handleUI()
        }
    }
    
    private var searchImage: UIImageView = {
        let obj = UIImageView()
        obj.image = UIImage(systemName: "magnifyingglass")
        obj.tintColor = .white
        
        return obj
    }()
    
    var searchLabel: UILabel = {
        let obj = UILabel()
        obj.font = FontConstants.regularFont_14
        
        return obj
    }()
    
    private var siteLogoImage: UIImageView = {
        let obj = UIImageView()
        
        return obj
    }()
    
    private var linkImage: UIImageView = {
        let obj = UIImageView()
        obj.image = UIImage(systemName: "arrow.up.left")
        obj.tintColor = .white
        
        return obj
    }()
    
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        setup()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setup() {
        self.backgroundColor = .clear
        contentView.addSubview(searchImage)
        contentView.addSubview(searchLabel)
        contentView.addSubview(siteLogoImage)
        contentView.addSubview(linkImage)
        
        setupConstraints()
    }
    
    private func setupConstraints() {
        searchImage.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(8.sizeH)
            make.leading.equalToSuperview().offset(8.sizeW)
            make.bottom.equalToSuperview().offset(-8.sizeH)
        }
        searchLabel.snp.makeConstraints { make in
            make.top.equalToSuperview().inset(8.sizeH)
            make.leading.equalTo(searchImage.snp.trailing).offset(8.sizeW)
        }
        siteLogoImage.snp.makeConstraints { make in
            make.top.equalToSuperview().inset(8.sizeH)
            make.height.width.equalTo(18.sizeH)
        }
        linkImage.snp.makeConstraints { make in
            make.top.equalToSuperview().inset(8.sizeH)
            make.leading.equalTo(siteLogoImage.snp.trailing).offset(8.sizeW)
            make.trailing.equalToSuperview().inset(8.sizeW)
        }
    }
}

extension SearchingTableViewCell {
    private func handleUI() {
        searchLabel.text = model
    }
}