ResidentTableViewCell.swift 4.59 KB
//
//  ResidentTableViewCell.swift
//  InterQR-Internship
//
//  Created by Дмитрий Тимофеев on 21.06.2022.
//

import UIKit

class ResidentTableViewCell: UITableViewCell {
    static let id = String(describing: ResidentTableViewCell.self)
    
    var containerView: UIView = {
        var obj = UIView()
        obj.layer.cornerRadius = 15
        obj.layer.borderWidth = 1
        obj.layer.borderColor = .BorderColor.lightGrey
        return obj
    }()
    
    var serialNumberView: UIImageView = {
        let obj = UIImageView()
        obj.layer.cornerRadius = 21.5
        obj.backgroundColor = .blue
        return obj
    }()
    
    var serialNumberLabel: UILabel = {
        let obj = UILabel()
        obj.font = .skModernist(type: .bold, ofSize: 14)
        obj.textColor = .white
        return obj
    }()
    
    var nameLabel: UILabel = {
        var obj = UILabel()
        obj.textColor = .TextColor.darkBlue
        obj.font = .skModernist(type: .bold, ofSize: 16)
        obj.text = "John Doe"
        return obj
    }()
    
    var phoneNumberLabel: UILabel = {
        var obj = UILabel()
        obj.textColor = .TextColor.lightGrey
        obj.font = .skModernist(type: .regular, ofSize: 14)
        obj.text = "+38095"
        return obj
    }()
    
    var managerButton: SquereCheckbox = {
        var obj = SquereCheckbox()
        obj.checkboxTitle = "Manager"
        obj.setTitleColor(.TextColor.lightGrey, for: .normal)
        obj.setTitleColor(.TextColor.darkBlue, for: .selected)
        obj.isSelected = false
        return obj
    }()
    
    var hiddenButton: SquereCheckbox = {
        var obj = SquereCheckbox()
        obj.checkboxTitle = "Hidden"
        obj.setTitleColor(.TextColor.lightGrey, for: .normal)
        obj.setTitleColor(.TextColor.darkBlue, for: .selected)
        obj.isSelected = false
        return obj
    }()
    
    var heartButton: UIButton = {
        var obj = UIButton()
        obj.setImage(UIImage(named: "Heart"), for: .normal)
        obj.setImage(UIImage(named: "RedHeart"), for: .selected)
        return obj
    }()
    
    var removeCellButton: UIButton = {
        var obj = UIButton()
        obj.setImage(UIImage(named: "Bin"), for: .normal)
        return obj
    }()
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        layout()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func layout() {
        selectionStyle = .none
        
        contentView.addSubview(containerView)
        containerView.addSubview(serialNumberView)
        serialNumberView.addSubview(serialNumberLabel)
        
        containerView.addSubview(nameLabel)
        containerView.addSubview(phoneNumberLabel)
        containerView.addSubview(managerButton)
        containerView.addSubview(hiddenButton)
        containerView.addSubview(heartButton)
        containerView.addSubview(removeCellButton)

        containerView.snp.makeConstraints {
            $0.leading.trailing.equalToSuperview().inset(25)
            $0.bottom.top.equalToSuperview().inset(8)
        }

        serialNumberView.snp.makeConstraints {
            $0.height.width.equalTo(41)
            $0.leading.equalToSuperview().offset(23)
            $0.top.equalToSuperview().offset(19)
        }
        
        serialNumberLabel.snp.makeConstraints {
            $0.centerX.centerY.equalToSuperview()
        }

        nameLabel.snp.makeConstraints {
            $0.leading.equalTo(serialNumberView.snp.trailing).offset(18)
            $0.top.equalToSuperview().offset(22)
        }

        removeCellButton.snp.makeConstraints {
            $0.centerY.equalTo(nameLabel.snp.centerY)
            $0.trailing.equalToSuperview().offset(-22.5)
        }

        phoneNumberLabel.snp.makeConstraints {
            $0.leading.equalTo(nameLabel.snp.leading)
            $0.top.equalTo(nameLabel.snp.bottom).offset(1)
        }

        managerButton.snp.makeConstraints {
            $0.top.equalTo(phoneNumberLabel.snp.bottom).offset(30)
            $0.leading.equalToSuperview().offset(24)
            $0.height.equalTo(20)
        }

        hiddenButton.snp.makeConstraints {
            $0.leading.equalTo(managerButton.snp.trailing).offset(23)
            $0.centerY.equalTo(managerButton)
            $0.height.equalTo(20)
        }

        heartButton.snp.makeConstraints {
            $0.centerY.equalTo(hiddenButton)
            $0.bottom.equalToSuperview().offset(-18)
            $0.trailing.equalToSuperview().offset(-22)
        }
    }
}