AnalysisItemViewCell.swift 3.57 KB
//
//  AnalysisItemViewCell.swift
//  SwiftWarplyFramework
//
//  Created by Manos Chorianopoulos on 18/7/22.
//

import UIKit

class AnalysisItemViewCell: UITableViewCell {

    @IBOutlet weak var dateLabel: UILabel!
    @IBOutlet weak var itemImage: UIImageView!
    @IBOutlet weak var titleLabel: UILabel!
    @IBOutlet weak var priceLabel: UILabel!
    @IBOutlet weak var subtitleLabel: UILabel!
    
    // lifecycle
    override func awakeFromNib() {
        super.awakeFromNib()
        
        // date
        dateLabel.textColor = UIColor(rgb: 0x435563)
        
        // title
        titleLabel.textColor = UIColor(rgb: 0x435563)
        
        // price
        priceLabel.textColor = UIColor(rgb: 0x435563)
        
        // subtitle
        subtitleLabel.textColor = UIColor(rgb: 0x8B97A3)
    }
}

extension AnalysisItemViewCell {
   func configureCell(item: swiftApi.SharingCouponModel) {

        let merchantList:Array<swiftApi.MerchantModel> = swiftApi().getMerchantList()

        titleLabel.text = ""

        for merchant in merchantList {
            if (merchant._uuid == item._merchant_uuid) {
               itemImage.load(link: merchant._img_preview, placeholder: UIImage(), cache: URLCache())
               titleLabel.text = merchant._admin_name
               break;
           }
        }
       
       dateLabel.text = item._date
        // titleLabel.text = item._name
       
       let priceFloat = Float(round(100 * (Float(item._discount) ?? 0.0)) / 100)
       var priceString = "0"
       priceString  = String(format: "%.2f", priceFloat).replacingOccurrences(of: ".", with: ",", options: .literal, range: nil)
       priceLabel.text = priceString + "€"
        
        if ("sent" == item._sharing_type) {
            subtitleLabel.text = String(format: "Εκπτωτικό κουπόνι προς " + item._receiver_msisdn)
        } else if ("received" == item._sharing_type) {
            subtitleLabel.text = String(format: "Εκπτωτικό κουπόνι από " + item._sender_msisdn)
        }
    }
    
    func configureCell(item: swiftApi.CouponItemModel) {
        
//        COUPONSET: desc, img_preview, name, terms, merchant_uuid
//        COUPON: coupon, expiration, discount, status
//        MERCHANT: _img_preview,_admin_name
                
        let merchantList:Array<swiftApi.MerchantModel> = swiftApi().getMerchantList()
        let couponSetData: swiftApi.CouponSetItemModel? = item.couponset_data
        
        titleLabel.text = ""
        
        for merchant in merchantList {
            if (merchant._uuid == couponSetData?.merchant_uuid) {
                itemImage.load(link: merchant._img_preview, placeholder: UIImage(), cache: URLCache())
                titleLabel.text = merchant._admin_name
                break;
            }
        }
        
        dateLabel.text = item.created ?? "" // expiration
//         itemImage.load(link: couponSetData?.img_preview ?? "", placeholder: UIImage(), cache: URLCache())
//         titleLabel.text = couponSetData?.name ?? ""
        
        let priceFloat = Float(round(100 * (Float(item.discount ?? "") ?? 0.0)) / 100)
        var priceString = "0"
        priceString  = String(format: "%.2f", priceFloat).replacingOccurrences(of: ".", with: ",", options: .literal, range: nil)
        priceLabel.text = priceString + "€"
         
        subtitleLabel.text = "Έκπτωτικό κουπόνι"
//        subtitleLabel.text = couponSetData?.short_description ?? ""
        // OR
//        let htmlText = couponSetData?.inner_text ?? ""
//        subtitleLabel.text = htmlText.htmlToString
        
     }
}