AnalysisHeaderMessageViewCell.swift 3.17 KB
//
//  AnalysisHeaderMessageViewCell.swift
//  SwiftWarplyFramework
//
//  Created by Manos Chorianopoulos on 18/7/22.
//

import UIKit

class AnalysisHeaderMessageViewCell: UITableViewCell {

    // attributes
    @IBOutlet weak var itemImage: UIImageView!
    @IBOutlet weak var messageLabel: UILabel!
    @IBOutlet weak var titleLabel: UILabel!
    @IBOutlet weak var emptyLabel: UILabel!
    
    public var loyaltyBadge:swiftApi.LoyaltyBadgeModel = swiftApi().getLoyaltyBadge()
    
    // lifecycle
    override func awakeFromNib() {
        super.awakeFromNib()
        
        // image
        itemImage.image = UIImage(named: "ic_gift_circle", in: Bundle(for: MyEmptyClass.self), compatibleWith: nil)
        
        // title
        titleLabel.textColor = UIColor(rgb: 0x435563)
        titleLabel.text = "Αναλυτικά:"
        
        // message
        messageLabel.textColor = UIColor(rgb: 0x435563)
        messageLabel.layer.borderWidth = 1.0
        messageLabel.layer.borderColor = UIColor(rgb: 0x1DA6B9).cgColor
        messageLabel.layer.cornerRadius = 5
        
        let totalCouponDiscount = Float(round(100 * loyaltyBadge._value) / 100)
        var totalCouponDiscountString = "0"
        totalCouponDiscountString  = String(format: "%.2f", totalCouponDiscount).replacingOccurrences(of: ".", with: ",", options: .literal, range: nil)
        
//        messageLabel.text = "Μέχρι τώρα έχεις κερδίσει " + totalCouponDiscountString + "€ σε προσφορές από " + String(loyaltyBadge._couponCount) + " κουπόνια!"

        let coupNormalText1 = "Μέχρι τώρα έχεις κερδίσει "
        let coupBoldText  = totalCouponDiscountString + "€"
        let coupNormalText2 = " σε προσφορές από "
        let coupBoldText2  = String(loyaltyBadge._couponCount)
        let coupNormalText3 = " κουπόνια!"

        let attrRegular = [NSAttributedString.Key.font : UIFont(name: "PFSquareSansPro-Regular", size: 17) ?? UIFont.systemFont(ofSize: 16)]
        let attrBold = [NSAttributedString.Key.font : UIFont(name: "PFSquareSansPro-Bold", size: 17) ?? UIFont.boldSystemFont(ofSize: 16)]
        
        let coupAttributedString = NSMutableAttributedString(string:coupNormalText1, attributes:attrRegular)
        let coupBoldString = NSMutableAttributedString(string: coupBoldText, attributes:attrBold)
        let coupNormalString2 = NSMutableAttributedString(string:coupNormalText2, attributes:attrRegular)
        let coupBoldString2 = NSMutableAttributedString(string: coupBoldText2, attributes:attrBold)
        let coupNormalString3 = NSMutableAttributedString(string:coupNormalText3, attributes:attrRegular)

        coupAttributedString.append(coupBoldString)
        coupAttributedString.append(coupNormalString2)
        coupAttributedString.append(coupBoldString2)
        coupAttributedString.append(coupNormalString3)
        messageLabel.attributedText = coupAttributedString
    }
}

extension AnalysisHeaderMessageViewCell {
    func configureCell(isEmpty: Bool) {
        
        if (isEmpty == true) {
            emptyLabel.isHidden = false
        } else {
            emptyLabel.isHidden = true
        }
        
    }
}