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

import UIKit

class SearchingTableViewCell: UITableViewCell {
    var model: String? {
        didSet {
            handleUI()
        }
    }
    
    var searchImage: UIImageView = {
        let obj = UIImageView()
        obj.image = UIImage(systemName: "magnifyingglass")
        obj.tintColor = .gray
        return obj
    }()
    
    var searchLabel: UILabel = {
        let obj = UILabel()
        obj.font = FontConstants.regularFont_14
        return obj
    }()
    
    var siteLogoImage: UIImageView = {
        let obj = UIImageView()
        return obj
    }()
    
    var linkImage: UIImageView = {
        let obj = UIImageView()
        obj.image = UIImage(systemName: "arrow.up.left")
        obj.tintColor = .gray
        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")
    }
    
    func setup() {
        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
//        if model?.siteLogo != UIImage() {
//            siteLogoImage.image = model?.siteLogo
//        } else {
//            siteLogoImage.image = UIImage()
//        }
    }
}