WalletVouchersBannerTableViewCell.swift 4.59 KB
//
//  WalletVouchersBannerTableViewCell.swift
//  SwiftWarplyFramework
//
//  Created by Manos Chorianopoulos on 23/10/23.
//

import UIKit
import SwiftEventBus

@objc public class WalletVouchersBannerTableViewCell: UITableViewCell {
    @IBOutlet weak var separatorView: UIView!
    @IBOutlet weak var separatorTopSpace: NSLayoutConstraint!
    @IBOutlet weak var sectionTitleLabel: UILabel!
    @IBOutlet weak var voucherBannerView: UIView!
    @IBOutlet weak var voucherBannerIconImage: UIImageView!
    @IBOutlet weak var voucherBannerLabel: UILabel!
    @IBOutlet weak var voucherBannerArrowImage: UIImageView!
    @IBOutlet weak var voucherCountView: UIView!
    
    let language = swiftApi().getLanguage()
    
    public override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        
        sectionTitleLabel.text = language == "en" ? "Subsidy balance" : "Υπόλοιπο επιδότησης"
        
        voucherBannerView.layer.cornerRadius = 16.0
        voucherBannerView.layer.borderWidth = 1
        voucherBannerView.layer.borderColor = UIColor(red: 0.90, green: 0.90, blue: 0.90, alpha: 1.00).cgColor
        
        // Add shadow
        voucherBannerView.layer.shadowColor = UIColor(red: 0.00, green: 0.00, blue: 0.00, alpha: 0.2).cgColor
        voucherBannerView.layer.shadowOffset = CGSize(width: 0.0, height: 1.0)
        voucherBannerView.layer.shadowOpacity = 1.0
        voucherBannerView.layer.shadowRadius = 1.0
        
        voucherBannerIconImage.image = UIImage(named: "wallet_voucher", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
        voucherBannerArrowImage.image = UIImage(named: "arrow_right_black", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
        
//        voucherBannerLabel.text = "Ενημερώσου για το υπόλοιπο επιδότησης"
        
        voucherCountView.layer.cornerRadius = 4.0
        // voucherCountView.backgroundColor = UIColor(red: 0.92, green: 0.75, blue: 0.41, alpha: 1.00)
        voucherCountView.backgroundColor = UIColor(rgb: 0xE20074)
    }

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

        // Configure the view for the selected state
    }
    
    func configureCell(showSeparator: Bool, active: Bool) {
        if (showSeparator == true) {
            separatorView.isHidden = false
            separatorTopSpace.constant = 25
            
        } else {
            separatorView.isHidden = true
            separatorTopSpace.constant = 0
        }
        
        if (active == true) {
            voucherBannerView.backgroundColor = .white
            voucherBannerIconImage.image = voucherBannerIconImage.image?.withRenderingMode(.alwaysTemplate)
            voucherBannerIconImage.tintColor = UIColor(red: 0.00, green: 0.65, blue: 0.89, alpha: 1.00)
            voucherBannerLabel.text = language == "en" ? "Check the available balance" : "Δες το διαθέσιμο υπόλοιπο"
            voucherBannerLabel.textColor = UIColor(red: 0.13, green: 0.13, blue: 0.13, alpha: 1.00)
            voucherBannerLabel.frame.size.width = voucherBannerLabel.intrinsicContentSize.width
            voucherCountView.isHidden = true
            
        } else {
            voucherBannerView.backgroundColor = UIColor(red: 0.95, green: 0.95, blue: 0.95, alpha: 1.00)
            voucherBannerIconImage.image = voucherBannerIconImage.image?.withRenderingMode(.alwaysTemplate)
            voucherBannerIconImage.tintColor = UIColor(red: 0.52, green: 0.52, blue: 0.52, alpha: 1.00)
            voucherBannerLabel.text = language == "en" ? "Available balance" : "Διαθέσιμο υπόλοιπο"
            voucherBannerLabel.textColor = UIColor(red: 0.52, green: 0.52, blue: 0.52, alpha: 1.00)
            voucherBannerLabel.frame.size.width = voucherBannerLabel.intrinsicContentSize.width
            voucherCountView.isHidden = false
        }
        
        setupAccessibilty(active: active, buttonTitle: voucherBannerLabel.text ?? "")
    }
    
    func setupAccessibilty (active: Bool ,buttonTitle: String) {
        // Disable accessibility for the whole cell
        self.isAccessibilityElement = false
        
        sectionTitleLabel.isAccessibilityElement = true
        
        voucherBannerView.isAccessibilityElement = true
        voucherBannerView.accessibilityLabel = buttonTitle + (!active ? ", 0" : "") + (!active ? ", Ανενεργό" : "")
        voucherBannerView.accessibilityHint = "Διπλό πάτημα για άνοιγμα"
        voucherBannerView.accessibilityTraits = .button
    }
    
}