AnalysisItemViewCell.swift 1.8 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) {
        
        // TODO: this is not optimal. we need a static date formatter. we cannot instantiate a new object each time we render a new item.
        let dateFormatter = DateFormatter()
        dateFormatter.dateFormat = "dd-MM-yyyy"
        
        if let date = item.date {
            let dateString = dateFormatter.string(from: date)
            dateLabel.text = dateString
        } else {
            dateLabel.text = ""
        }
        
        //itemImage.image =
        titleLabel.text = item.name
        priceLabel.text = String(format: "%.2f€", item.discount)
        
        if ("sent" == item.sharingType) {
            subtitleLabel.text = String(format: "Εκπτωτικό κουπόνι προς @%", "69740000000")
        } else if ("received" == item.sharingType) {
            subtitleLabel.text = String(format: "Εκπτωτικό κουπόνι από @%", "69740000000")
        }
    }
}