import UIKit

/// person header view
class OsobaHeaderView: UIView {
    
    let nameTitle: UILabel = {
        let view = UILabel()
        view.translatesAutoresizingMaskIntoConstraints = false
        view.font = UIFont.systemFont(ofSize: 24)
        view.textColor = scoutBlue
        return view
    }()
    
    let phoneTitle: UILabel = {
        let view = UILabel()
        view.translatesAutoresizingMaskIntoConstraints = false
        view.font = UIFont.systemFont(ofSize: 20)
        view.textColor = scoutOrange
        return view
    }()
    
    let emailTitle: UILabel = {
        let view = UILabel()
        view.translatesAutoresizingMaskIntoConstraints = false
        view.font = UIFont.systemFont(ofSize: 20)
        view.textColor = scoutOrange
        return view
    }()
    
    let profilePicture: UIImageView = {
        let view = UIImageView()
        view.translatesAutoresizingMaskIntoConstraints = false
        view.contentMode = .scaleAspectFit
        view.layer.cornerRadius = 15
        view.clipsToBounds = true
        return view
    }()
    
    private let separator: UIView = {
        let view = UIView()
        view.backgroundColor = .black
        view.translatesAutoresizingMaskIntoConstraints = false
        view.heightAnchor.constraint(equalToConstant: 1).isActive = true
        return view
    }()
    
    /// initialization function
    /// - Parameter frame: frame
    override init(frame: CGRect) {
        super.init(frame: frame)
        addSubview(nameTitle)
        addSubview(emailTitle)
        addSubview(phoneTitle)
        addSubview(profilePicture)
        addSubview(separator)
        setupConstraints()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    /// funciton that sets up constraints for the header view
    private func setupConstraints() {
        NSLayoutConstraint.activate([
            nameTitle.topAnchor.constraint(equalTo: topAnchor, constant: 12),
            nameTitle.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 12),
            nameTitle.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -80),
            
            emailTitle.topAnchor.constraint(equalTo: nameTitle.bottomAnchor, constant: 12),
            emailTitle.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 12),
            emailTitle.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -80),
                        
            phoneTitle.topAnchor.constraint(equalTo: emailTitle.bottomAnchor, constant: 12),
            phoneTitle.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 12),
            phoneTitle.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -80),
            phoneTitle.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -12),
            
            profilePicture.topAnchor.constraint(equalTo: nameTitle.topAnchor),
            profilePicture.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -8),
            profilePicture.leadingAnchor.constraint(equalTo: trailingAnchor, constant: -80),
            profilePicture.bottomAnchor.constraint(equalTo: separator.topAnchor, constant: -8),
            
            separator.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 12),
            separator.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -12),
            separator.bottomAnchor.constraint(equalTo: bottomAnchor)
        ])
    }
}
