//
//  UserNotificationCell.swift
//  WOKA
//
//  Created by MacBook Pro on 13/06/24.
//

import UIKit

class UserNotificationCell: UITableViewCell {

    @IBOutlet weak var notificationDate: UILabel!
    @IBOutlet weak var notificationDesc: UILabel!
    
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

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

        // Configure the view for the selected state
    }
    
    
    func setData(data : UserNotificationDM){
        if let dateStr = data.createdAt, let date = DateFormatterLib.dateMods(dateStr: dateStr, dateCurrentFormat: .yyyy_MM_ddTHH_mm_ss_ssZ, dateReturnFormat: .yyyy_MM_ddTHH_mm_ss_ssZ, stringOrDate: .date).1{
            let currentDate = Date()

            // Calculate the difference in days
            let calendar = Calendar.current
            let dateComponents = calendar.dateComponents([.day], from: currentDate, to: date)

            if let daysDifference = dateComponents.day {
                let datePositive = abs(daysDifference)
                if datePositive == 0{
                    notificationDate.text = "Today"
                }else if datePositive == 1{
                    notificationDate.text = "Yesterday"
                }else{
                    notificationDate.text = datePositive.toString() + " days ago"
                }
            } else {
                notificationDate.text = "0 days ago"
            }
        }
        notificationDesc.text = data.title
    }
}
