//
//  ExternalLink.swift
//  MVMCoreUI
//
//  Created by Kevin Christiano on 2/20/20.
//  Copyright © 2020 Verizon Wireless. All rights reserved.
//

import UIKit


open class ExternalLink: Link {
    //--------------------------------------------------
    // MARK: - Public Properties
    //--------------------------------------------------
    open var exportImageView: UIImageView?
    open var exportImageHeight: NSLayoutConstraint?
    open var exportImageWidth: NSLayoutConstraint?

    //--------------------------------------------------
    // MARK: - Overrides
    //--------------------------------------------------
    open override func viewModelDidUpdate() {
        super.viewModelDidUpdate()
        exportImageView?.tintColor = textColor
        exportImageWidth?.constant = textStyle.lineHeight
        exportImageHeight?.constant = textStyle.lineHeight
    }
        
    open override func setup() {
        super.setup()
        contentHorizontalAlignment = .left

        let image = MVMCoreUIUtility.imageNamed("externalLink")
        exportImageView = UIImageView(image: image?.withRenderingMode(.alwaysTemplate))
        
        guard let exportIcon = exportImageView else { return }
        
        exportIcon.contentMode = .scaleAspectFit
        exportIcon.translatesAutoresizingMaskIntoConstraints = false
        
        addSubview(exportIcon)
        trailingAnchor.constraint(greaterThanOrEqualTo: exportIcon.trailingAnchor).isActive = true
        
        exportImageHeight = exportIcon.heightAnchor.constraint(equalToConstant: textStyle.pointSize).activate()
        exportImageWidth = exportIcon.widthAnchor.constraint(equalToConstant: textStyle.pointSize).activate()
        
        if let titleLabel {
            exportIcon.leadingAnchor.constraint(equalTo: titleLabel.trailingAnchor, constant: 4).isActive = true
            exportIcon.bottomAnchor.constraint(equalTo: titleLabel.lastBaselineAnchor, constant: 3).isActive = true
        }
    }
}
