<commit_before>//
//  PXSummaryCompactComponentView.swift
//  MercadoPagoSDK
//
//  Created by <NAME> on 2/3/18.
//  Copyright © 2018 MercadoPago. All rights reserved.
//

import Foundation

final class PXSummaryCompactComponentView: PXComponentView {
    static let TITLE_FONT_SIZE: CGFloat = PXLayout.XXXL_FONT
    static let CUSTOM_TITLE_FONT_SIZE: CGFloat = PXLayout.XS_FONT
    
    fileprivate let PERCENT_SCREEN_WIDTH: CGFloat = 86
    fileprivate let TOP_BOTTOM_MARGIN: CGFloat = PXLayout.L_MARGIN
    fileprivate let INTER_MARGIN: CGFloat = 9
    
    fileprivate var totalLabel: UILabel?
    fileprivate var customTextLabel: UILabel?
}

extension PXSummaryCompactComponentView {
    
    func buildView(amountAttributeText: NSAttributedString, bottomCustomTitle: NSAttributedString, textColor: UIColor, backgroundColor: UIColor) -> CGFloat {
        
        self.backgroundColor = backgroundColor
        
        let screenWidth = PXLayout.getScreenWidth(applyingMarginFactor: PERCENT_SCREEN_WIDTH)
        
        let (tLabel, cLabel) = buildLabels(amountText: amountAttributeText, customText: bottomCustomTitle, in: self, textColor: textColor)
        
        let titleHeight = UILabel.requiredHeight(forAttributedText: amountAttributeText, withFont: Utils.getFont(size: PXSummaryCompactComponentView.TITLE_FONT_SIZE), inNumberOfLines: 1, inWidth: screenWidth)
        PXLayout.setHeight(owner: tLabel, height: titleHeight).isActive = true
        
        let customTitleHeight = UILabel.requiredHeight(forAttributedText: bottomCustomTitle, withFont: Utils.getFont(size: PXSummaryCompactComponentView.CUSTOM_TITLE_FONT_SIZE), inNumberOfLines: 3, inWidth: screenWidth)
        PXLayout.setHeight(owner: cLabel, height: customTitleHeight).isActive = true
        
        totalLabel = tLabel
        customTextLabel = cLabel
        
        return titleHeight + customTitleHeight + INTER_MARGIN + TOP_BOTTOM_MARGIN*2
    }
    
    fileprivate func buildLabels(amountText: NSAttributedString?, customText: NSAttributedString?, in superView: UIView, textColor: UIColor) -> (UILabel, UILabel) {
        
        let amountLabel = UILabel()
        amountLabel.translatesAutoresizingMaskIntoConstraints = false
        amountLabel.textAlignment = .center
        amountLabel.numberOfLines = 1
        amountLabel.attributedText = amountText
        amountLabel.textColor = textColor
        superView.addSubview(amountLabel)
        
        PXLayout.pinTop(view: amountLabel, to: superView, withMargin: PXLayout.L_MARGIN).isActive = true
        PXLayout.centerHorizontally(view: amountLabel).isActive = true
        PXLayout.matchWidth(ofView: amountLabel, withPercentage: PERCENT_SCREEN_WIDTH).isActive = true
        
        let customTitleLabel = UILabel()
        customTitleLabel.translatesAutoresizingMaskIntoConstraints = false
        customTitleLabel.textAlignment = .center
        customTitleLabel.numberOfLines = 3
        customTitleLabel.lineBreakMode = .byTruncatingTail
        customTitleLabel.attributedText = customText<commit_msg>Get number of lines from label<commit_after>//
//  PXSummaryCompactComponentView.swift
//  MercadoPagoSDK
//
//  Created by <NAME> on 2/3/18.
//  Copyright © 2018 MercadoPago. All rights reserved.
//

import Foundation

final class PXSummaryCompactComponentView: PXComponentView {
    static let TITLE_FONT_SIZE: CGFloat = PXLayout.XXXL_FONT
    static let CUSTOM_TITLE_FONT_SIZE: CGFloat = PXLayout.XS_FONT
    
    fileprivate let PERCENT_SCREEN_WIDTH: CGFloat = 86
    fileprivate let TOP_BOTTOM_MARGIN: CGFloat = PXLayout.L_MARGIN
    fileprivate let INTER_MARGIN: CGFloat = 9
    
    fileprivate var totalLabel: UILabel?
    fileprivate var customTextLabel: UILabel?
}

extension PXSummaryCompactComponentView {
    
    func buildView(amountAttributeText: NSAttributedString, bottomCustomTitle: NSAttributedString, textColor: UIColor, backgroundColor: UIColor) -> CGFloat {
        
        self.backgroundColor = backgroundColor
        
        let screenWidth = PXLayout.getScreenWidth(applyingMarginFactor: PERCENT_SCREEN_WIDTH)
        
        let (tLabel, cLabel) = buildLabels(amountText: amountAttributeText, customText: bottomCustomTitle, in: self, textColor: textColor)
        
        let titleHeight = UILabel.requiredHeight(forAttributedText: amountAttributeText, withFont: Utils.getFont(size: PXSummaryCompactComponentView.TITLE_FONT_SIZE), inNumberOfLines: tLabel.numberOfLines, inWidth: screenWidth)
        PXLayout.setHeight(owner: tLabel, height: titleHeight).isActive = true
        
        let customTitleHeight = UILabel.requiredHeight(forAttributedText: bottomCustomTitle, withFont: Utils.getFont(size: PXSummaryCompactComponentView.CUSTOM_TITLE_FONT_SIZE), inNumberOfLines: cLabel.numberOfLines, inWidth: screenWidth)
        PXLayout.setHeight(owner: cLabel, height: customTitleHeight).isActive = true
        
        totalLabel = tLabel
        customTextLabel = cLabel
        
        return titleHeight + customTitleHeight + INTER_MARGIN + TOP_BOTTOM_MARGIN*2
    }
    
    fileprivate func buildLabels(amountText: NSAttributedString?, customText: NSAttributedString?, in superView: UIView, textColor: UIColor) -> (UILabel, UILabel) {
        
        let amountLabel = UILabel()
        amountLabel.translatesAutoresizingMaskIntoConstraints = false
        amountLabel.textAlignment = .center
        amountLabel.numberOfLines = 1
        amountLabel.attributedText = amountText
        amountLabel.textColor = textColor
        superView.addSubview(amountLabel)
        
        PXLayout.pinTop(view: amountLabel, to: superView, withMargin: PXLayout.L_MARGIN).isActive = true
        PXLayout.centerHorizontally(view: amountLabel).isActive = true
        PXLayout.matchWidth(ofView: amountLabel, withPercentage: PERCENT_SCREEN_WIDTH).isActive = true
        
        let customTitleLabel = UILabel()
        customTitleLabel.translatesAutoresizingMaskIntoConstraints = false
        customTitleLabel.textAlignment = .center
        customTitleLabel.numberOfLines = 3
        customTitleLabel.lineBreakMode = .byTruncatingTail
        customTitleLabel.attributedText = customText
{'fraction_non_alphanumeric': 0.0675610150315177, 'fraction_numerical': 0.004848876676903184, 'mean_word_length': 3.752688172043011, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3750261', 'n_tokens_mistral': 1870, 'n_tokens_neox': 1799, 'n_words': 362}