<commit_before>//
//  AdditionalStepViewController.swift
//  MercadoPagoSDK
//
//  Created by <NAME> on 10/13/16.
//  Copyright © 2016 MercadoPago. All rights reserved.
//

import UIKit

open class AdditionalStepViewController: MercadoPagoUIScrollViewController, UITableViewDelegate,UITableViewDataSource {
    
    @IBOutlet weak var tableView: UITableView!
    
    var bundle : Bundle? = MercadoPago.getBundle()
    let viewModel : AdditionalStepViewModel!
    override var maxFontSize: CGFloat { get { return self.viewModel.maxFontSize } }
  
    override open var screenName : String { get { return viewModel.getScreenName()} }
    
    override open func viewDidLoad() {
        super.viewDidLoad()
        tableView.tableFooterView = UIView()
        tableView.separatorStyle = .none
        loadMPStyles()
        
        var upperFrame = UIScreen.main.bounds
        upperFrame.origin.y = -upperFrame.size.height;
        let upperView = UIView(frame: upperFrame)
        upperView.backgroundColor = UIColor.primaryColor()
        tableView.addSubview(upperView)
        
        self.showNavBar()
        loadCells()
    }
    
    func loadCells() {
        let titleNib = UINib(nibName: "AdditionalStepTitleTableViewCell", bundle: self.bundle)
        self.tableView.register(titleNib, forCellReuseIdentifier: "titleNib")
        let cardNib = UINib(nibName: "AdditionalStepCardTableViewCell", bundle: self.bundle)
        self.tableView.register(cardNib, forCellReuseIdentifier: "cardNib")
        let totalRowNib = UINib(nibName: "TotalPayerCostRowTableViewCell", bundle: self.bundle)
        self.tableView.register(totalRowNib, forCellReuseIdentifier: "totalRowNib")
        let bankInsterestNib = UINib(nibName: "BankInsterestTableViewCell", bundle: self.bundle)
        self.tableView.register(bankInsterestNib, forCellReuseIdentifier: "bankInsterestNib")
    }
    
    open override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.hideNavBar()
    }
    
    override open func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        self.title = ""
        self.navigationItem.leftBarButtonItem!.action = #selector(invokeCallbackCancel)
        self.extendedLayoutIncludesOpaqueBars = true
        self.titleCellHeight = 44
    }
    
    override func loadMPStyles(){
        if self.navigationController != nil {
            self.navigationController!.interactivePopGestureRecognizer?.delegate = self
            self.navigationController?.navigationBar.tintColor = UIColor(red: 255, green: 255, blue: 255)
            self.navigationController?.navigationBar.barTintColor = UIColor.primaryColor()
            self.navigationController?.navigationBar.removeBottomLine()
            self.navigationController?.navigationBar.isTranslucent = false
            
            displayBackButton()
        }
    }
    
    required public init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    public init(viewModel : AdditionalStepViewModel, callback: @escaping ((_ callbackData: NSObject)-> Void)) {
        self.viewModel = viewModel
        self.viewModel.callback = callback
        super.init(nibName: "AdditionalStepViewController", bundle: self.bundle)
    }
    
    public func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return self.viewModel.heightForRowAt(indexPath: indexPath)
    }
    
    public func numberOfSections(in tableView: UITableView) -> Int {
        return 4
    }
    
    public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return  self.viewModel.numberOfRowsInSection(section: section)
    }
    
    public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cellWidth = self.tableView.bounds.width
        
        if viewModel.isTitleCellFor(indexPath: indexPath) {
            
            let titleCell = tableView.dequeueReusableCell(withIdentifier: "titleNib", for: indexPath as IndexPath) as! AdditionalStepTitleTableViewCell
            titleCell.selectionStyle = .none
            titleCell.setTitle(string: self.getNavigationBarTitle())
            titleCell.backgroundColor = UIColor.primaryColor()
            self.titleCell = titleCell
            
            return titleCell
            
        } else if viewModel.isCardSectionFor(indexPath: indexPath) {
            
            if viewModel.isCardCellFor(indexPath: indexPath) {
            
                if viewModel.showCardSection(), let cellView = viewModel.getCardSectionView() {
                    
                    let cardSectionCell = tableView.dequeueReusableCell(withIdentifier: "cardNib", for: indexPath as IndexPath) as! AdditionalStepCardTableViewCell
                    cardSectionCell.loadCellView(view: cellView as! UIView)
                    cardSectionCell.selectionStyle = .none
                    cardSectionCell.updateCardSkin(token: self.viewModel.token, paymentMethod: self.viewModel.paymentMethods[0], view: cellView)
                    cardSectionCell.backgroundColor = UIColor.primaryColor()
                    
                    return cardSectionCell
                    
                }else{
                    let cardSectionCell = tableView.dequeueReusableCell(withIdentifier: "cardNib", for: indexPath as IndexPath) as! AdditionalStepCardTableViewCell
                    cardSectionCell.loadCellView(view: nil)
                    cardSectionCell.backgroundColor = UIColor.primaryColor()
                    return cardSectionCell
                }
                
            } else {
                let bankInsterestCell = tableView.dequeueReusableCell(withIdentifier: "bankInsterestNib", for: indexPath as IndexPath) as! BankInsterestTableViewCell
                bankInsterestCell.backgroundColor = UIColor.primaryColor()
                return bankInsterestCell
        }
            
        } else if viewModel.isDiscountCellFor(indexPath: indexPath) {
            let cell = UITableViewCell.init(style: .default, reuseIdentifier: "CouponCell")
            cell.contentView.viewWithTag(1)?.removeFromSuperview()
            let discountBody = DiscountBodyCell(frame: CGRect(x: 0, y: 0, width : view.frame.width, height : DiscountBodyCell.HEIGHT), coupon: self.viewModel.discount, amount:self.viewModel.amount)
            discountBody.tag = 1
            cell.contentView.addSubview(discountBody)
            cell.selectionStyle = .none
            return cell
            
        } else if viewModel.isTotalCellFor(indexPath: indexPath) {
            let cellHeight = Double(viewModel.getAmountDetailCellHeight(indexPath: indexPath))<commit_msg>AdditionalStepViewController Requested Changes<commit_after>//
//  AdditionalStepViewController.swift
//  MercadoPagoSDK
//
//  Created by <NAME> on 10/13/16.
//  Copyright © 2016 MercadoPago. All rights reserved.
//

import UIKit

open class AdditionalStepViewController: MercadoPagoUIScrollViewController, UITableViewDelegate,UITableViewDataSource {
    
    @IBOutlet weak var tableView: UITableView!
    
    var bundle : Bundle? = MercadoPago.getBundle()
    let viewModel : AdditionalStepViewModel!
    override var maxFontSize: CGFloat { get { return self.viewModel.maxFontSize } }
  
    override open var screenName : String { get { return viewModel.getScreenName()} }
    
    override open func viewDidLoad() {
        super.viewDidLoad()
        tableView.tableFooterView = UIView()
        tableView.separatorStyle = .none
        loadMPStyles()
        
        var upperFrame = UIScreen.main.bounds
        upperFrame.origin.y = -upperFrame.size.height;
        let upperView = UIView(frame: upperFrame)
        upperView.backgroundColor = UIColor.primaryColor()
        tableView.addSubview(upperView)
        
        self.showNavBar()
        loadCells()
    }
    
    func loadCells() {
        let titleNib = UINib(nibName: "AdditionalStepTitleTableViewCell", bundle: self.bundle)
        self.tableView.register(titleNib, forCellReuseIdentifier: "titleNib")
        let cardNib = UINib(nibName: "AdditionalStepCardTableViewCell", bundle: self.bundle)
        self.tableView.register(cardNib, forCellReuseIdentifier: "cardNib")
        let totalRowNib = UINib(nibName: "TotalPayerCostRowTableViewCell", bundle: self.bundle)
        self.tableView.register(totalRowNib, forCellReuseIdentifier: "totalRowNib")
        let bankInsterestNib = UINib(nibName: "BankInsterestTableViewCell", bundle: self.bundle)
        self.tableView.register(bankInsterestNib, forCellReuseIdentifier: "bankInsterestNib")
    }
    
    open override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.hideNavBar()
    }
    
    override open func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        self.title = ""
        self.navigationItem.leftBarButtonItem!.action = #selector(invokeCallbackCancel)
        self.extendedLayoutIncludesOpaqueBars = true
        self.titleCellHeight = 44
    }
    
    override func loadMPStyles(){
        if self.navigationController != nil {
            self.navigationController!.interactivePopGestureRecognizer?.delegate = self
            self.navigationController?.navigationBar.tintColor = UIColor(red: 255, green: 255, blue: 255)
            self.navigationController?.navigationBar.barTintColor = UIColor.primaryColor()
            self.navigationController?.navigationBar.removeBottomLine()
            self.navigationController?.navigationBar.isTranslucent = false
            
            displayBackButton()
        }
    }
    
    required public init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    public init(viewModel : AdditionalStepViewModel, callback: @escaping ((_ callbackData: NSObject)-> Void)) {
        self.viewModel = viewModel
        self.viewModel.callback = callback
        super.init(nibName: "AdditionalStepViewController", bundle: self.bundle)
    }
    
    public func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return self.viewModel.heightForRowAt(indexPath: indexPath)
    }
    
    public func numberOfSections(in tableView: UITableView) -> Int {
        return 4
    }
    
    public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return  self.viewModel.numberOfRowsInSection(section: section)
    }
    
    public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cellWidth = self.tableView.bounds.width
        
        if viewModel.isTitleCellFor(indexPath: indexPath) {
            
            let titleCell = tableView.dequeueReusableCell(withIdentifier: "titleNib", for: indexPath as IndexPath) as! AdditionalStepTitleTableViewCell
            titleCell.selectionStyle = .none
            titleCell.setTitle(string: self.getNavigationBarTitle())
            titleCell.backgroundColor = UIColor.primaryColor()
            self.titleCell = titleCell
            
            return titleCell
            
        } else if viewModel.isCardCellFor(indexPath: indexPath) {
            
            if viewModel.showCardSection(), let cellView = viewModel.getCardSectionView() {
                let cardSectionCell = tableView.dequeueReusableCell(withIdentifier: "cardNib", for: indexPath as IndexPath) as! AdditionalStepCardTableViewCell
                cardSectionCell.loadCellView(view: cellView as? UIView)
                cardSectionCell.selectionStyle = .none
                cardSectionCell.updateCardSkin(token: self.viewModel.token, paymentMethod: self.viewModel.paymentMethods[0], view: cellView)
                cardSectionCell.backgroundColor = UIColor.primaryColor()
                
                return cardSectionCell
                
            }else{
                
                let cardSectionCell = tableView.dequeueReusableCell(withIdentifier: "cardNib", for: indexPath as IndexPath) as! AdditionalStepCardTableViewCell
                cardSectionCell.loadCellView(view: nil)
                cardSectionCell.backgroundColor = UIColor.primaryColor()
                return cardSectionCell
            }
            
        } else if viewModel.isBankInterestCellFor(indexPath: indexPath){
            
                let bankInsterestCell = tableView.dequeueReusableCell(withIdentifier: "bankInsterestNib", for: indexPath as IndexPath) as! BankInsterestTableViewCell
                bankInsterestCell.backgroundColor = UIColor.primaryColor()
                return bankInsterestCell
            
        } else if viewModel.isDiscountCellFor(indexPath: indexPath) {
            let cell = UITableViewCell.init(style: .default, reuseIdentifier: "CouponCell")
            cell.contentView.viewWithTag(1)?.removeFromSuperview()
            let discountBody = DiscountBodyCell(frame: CGRect(x: 0, y: 0, width : view.frame.width, height : DiscountBodyCell.HEIGHT), coupon: self.viewModel.discount, amount:self.viewModel.amount)
            discountBody.tag = 1
            cell.contentView.addSubview(discountBody)
            cell.selectionStyle = .none
            return cell
            
        } else if viewModel.isTotalCellFor(indexPath: indexPath) {
            let cellHeight = Double(viewModel.getAmountDetailCellHeight(indexPath: indexPath))
{'fraction_non_alphanumeric': 0.07987008193696021, 'fraction_numerical': 0.00398612238872075, 'mean_word_length': 2.693565976008724, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '417179', 'n_tokens_mistral': 3765, 'n_tokens_neox': 3607, 'n_words': 715}