WalletBadgesTableViewCell.swift 4.15 KB
//
//  WalletBadgesTableViewCell.swift
//  SwiftWarplyFramework
//
//  Created by Manos Chorianopoulos on 5/4/23.
//

import UIKit

@objc public class WalletBadgesTableViewCell: UITableViewCell {
    @IBOutlet weak var rewardsLabel: UILabel!
    @IBOutlet weak var badgeLinesImage: UIImageView!
    @IBOutlet weak var sumBadgeImage: UIImageView!
    @IBOutlet weak var sumBadgeLabel: UILabel!
    @IBOutlet weak var dfyBadgeImage: UIImageView!
    @IBOutlet weak var dfyBadgeLabel: UILabel!
    @IBOutlet weak var couponBadgeImage: UIImageView!
    @IBOutlet weak var couponBadgeLabel: UILabel!
    @IBOutlet weak var marketBadgeImage: UIImageView!
    @IBOutlet weak var marketBadgeLabel: UILabel!
    
    public var loyaltyBadge:swiftApi.LoyaltyBadgeModel = swiftApi().getLoyaltyBadge()
    
    public override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        
         sumBadgeImage.image = UIImage(named: "wallet_summary", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
         badgeLinesImage.image = UIImage(named: "wallet_badge_lines", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
        
        rewardsLabel.text = "COSMOTE Επιβράβευση"
    }

    public override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    func configureCell(totalCouponValue: Float, totalCouponDiscount: Float, unifiedCouponsDiscount: Float) {
        
        let sumRewards = totalCouponValue + totalCouponDiscount + unifiedCouponsDiscount
//        sumRewards = Float(round(100 * sumRewards) / 100)
        var sumRewardsString = "0"
        sumRewardsString = String(format: "%.2f", sumRewards).replacingOccurrences(of: ".", with: ",", options: .literal, range: nil)
        sumBadgeLabel.text = sumRewardsString + "€"
        
        // ===
        
        if (totalCouponValue == 0.0) {
            dfyBadgeImage.image = UIImage(named: "wallet_dfy_empty", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
            dfyBadgeLabel.isHidden = true
            
        } else {
            dfyBadgeImage.image = UIImage(named: "wallet_dfy_2", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
            dfyBadgeLabel.isHidden = false
        }
        
        let totalCouponValueFixed = Float(round(100 * totalCouponValue) / 100)
        var totalCouponValueString = "0"
        totalCouponValueString = String(format: "%.2f", totalCouponValueFixed).replacingOccurrences(of: ".", with: ",", options: .literal, range: nil)
        dfyBadgeLabel.text = totalCouponValueString + "€"
        
        // ===
        
        if (loyaltyBadge._couponCount == 0) {
            couponBadgeImage.image = UIImage(named: "wallet_coupons_empty", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
            couponBadgeLabel.isHidden = true
        } else {
            couponBadgeImage.image = UIImage(named: "wallet_coupons_3", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
            couponBadgeLabel.isHidden = false
        }
        
        var totalCouponDiscountString = "0"
        totalCouponDiscountString  = String(format: "%.2f", totalCouponDiscount).replacingOccurrences(of: ".", with: ",", options: .literal, range: nil)
        couponBadgeLabel.text = totalCouponDiscountString + "€"
        
        // ===
        
        let marketDiscount = Float(round(100 * unifiedCouponsDiscount) / 100)
        var marketDiscountString = "0"
        marketDiscountString  = String(format: "%.2f", marketDiscount).replacingOccurrences(of: ".", with: ",", options: .literal, range: nil)
    
        self.marketBadgeLabel.text = marketDiscountString + "€"
        
        if (unifiedCouponsDiscount == 0.0) {
            marketBadgeImage.image = UIImage(named: "wallet_market_empty", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
            marketBadgeLabel.isHidden = true
            
        } else {
            marketBadgeImage.image = UIImage(named: "wallet_market", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
            marketBadgeLabel.isHidden = false
        }
        
    }

}