MyRewardsOfferCollectionViewCell.swift 4.75 KB
//
//  MyRewardsOfferCollectionViewCell.swift
//  SwiftWarplyFramework
//
//  Created by Manos Chorianopoulos on 26/5/25.
//

import UIKit

@objc(MyRewardsOfferCollectionViewCell)
public class MyRewardsOfferCollectionViewCell: UICollectionViewCell {
    @IBOutlet weak var parentView: UIView!
    @IBOutlet weak var bannerImage: UIImageView!
    @IBOutlet weak var favoriteImage: UIImageView!
    @IBOutlet weak var discountView: UIView!
    @IBOutlet weak var discountLabel: UILabel!
    @IBOutlet weak var titleLabel: UILabel!
    @IBOutlet weak var subtitleLabel: UILabel!
    @IBOutlet weak var expirationLabel: UILabel!
    @IBOutlet weak var logoImage: UIImageView!
    
    public override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        
        parentView.layer.borderWidth = 1.0
        parentView.layer.borderColor = UIColor(rgb: 0xCCCCCC).cgColor
        parentView.layer.cornerRadius = 8.0
        parentView.clipsToBounds = true
        
        discountView.layer.cornerRadius = 34.0
        
    }
    
    func configureCell(data: OfferModel) {
        bannerImage.image = UIImage(named: data.bannerImage, in: Bundle.frameworkResourceBundle, compatibleWith: nil)
        favoriteImage.image = UIImage(named: data.isFavorite ? "favorite_filled" : "favorite_empty", in: Bundle.frameworkResourceBundle, compatibleWith: nil)
        
        let discountSymbol =
            data.discountType == "percentage" ? "%"
            : data.discountType == "price" ? "€"
            : data.discountType == "buyOneGetOne" ? "1+1"
            : data.discountType == "free" ? "Δωρεάν"
            : ""
        
//        discountLabel.text = "\(data.discount)\(discountSymbol)"
        discountLabel.text = data.discount
        discountLabel.font = UIFont(name: "PingLCG-Bold", size: 17)
        discountLabel.textColor = UIColor(rgb: 0xF2F2F2)
        
        discountView.backgroundColor = UIColor(rgb: data.color)
        
        titleLabel.text = data.title
        titleLabel.font = UIFont(name: "PingLCG-Bold", size: 17)
        titleLabel.textColor = UIColor(rgb: 0x000F1E)
        
        subtitleLabel.text = data.description
        subtitleLabel.font = UIFont(name: "PingLCG-Regular", size: 14)
        subtitleLabel.textColor = UIColor(rgb: 0x00111B)
        
        expirationLabel.text = data.expirationDate
        expirationLabel.font = UIFont(name: "PingLCG-Regular", size: 13)
        expirationLabel.textColor = UIColor(rgb: 0x00111B)
        
        logoImage.image = UIImage(named: data.merchantLogo, in: Bundle.frameworkResourceBundle, compatibleWith: nil)
    }
    
    
    func configureCell(data: CouponSetItemModel) {
        // Use coupon set preview image
        let imageName = data.img_preview ?? ""
        if !imageName.isEmpty {
            bannerImage.image = UIImage(named: imageName, in: Bundle.frameworkResourceBundle, compatibleWith: nil)
        } else {
            bannerImage.image = nil
        }
        
        // Default to not favorite for coupon sets
        favoriteImage.image = UIImage(named: "favorite_empty", in: Bundle.frameworkResourceBundle, compatibleWith: nil)
        
        // Use coupon set discount
        discountLabel.text = data.discount ?? ""
        discountLabel.font = UIFont(name: "PingLCG-Bold", size: 17)
        discountLabel.textColor = UIColor(rgb: 0xF2F2F2)
        
        // Color based on discount type
        let discountColor: UInt = {
            switch data.discount_type {
            case "percentage":
                return 0xFF6B35
            case "value":
                return 0x28A745
            case "plus_one":
                return 0x007AFF
            default:
                return 0x6C757D
            }
        }()
        discountView.backgroundColor = UIColor(rgb: discountColor)
        
        titleLabel.text = data.name ?? ""
        titleLabel.font = UIFont(name: "PingLCG-Bold", size: 17)
        titleLabel.textColor = UIColor(rgb: 0x000F1E)
        
        subtitleLabel.text = data.short_description ?? ""
        subtitleLabel.font = UIFont(name: "PingLCG-Regular", size: 14)
        subtitleLabel.textColor = UIColor(rgb: 0x00111B)
        
        expirationLabel.text = data.expiration ?? ""
        expirationLabel.font = UIFont(name: "PingLCG-Regular", size: 13)
        expirationLabel.textColor = UIColor(rgb: 0x00111B)
        
        // Use first image from img array if available
        if let imgArray = data.img, !imgArray.isEmpty {
            let logoName = imgArray[0]
            if !logoName.isEmpty {
                logoImage.image = UIImage(named: logoName, in: Bundle.frameworkResourceBundle, compatibleWith: nil)
            } else {
                logoImage.image = nil
            }
        } else {
            logoImage.image = nil
        }
    }
    
}