//
//  AddressCell.swift
//  WOKA
//
//  Created by MacBook Pro on 25/07/24.
//

import UIKit

class AddressCell: UITableViewCell {

    @IBOutlet weak var addressName: LocalisedElementsLabel!
    @IBOutlet weak var addressLine: LocalisedElementsLabel!
    @IBOutlet weak var phoneNo: LocalisedElementsLabel!
    @IBOutlet weak var expecteDelivery: LocalisedElementsLabel!
    @IBOutlet weak var radioImage: UIImageView!
    @IBOutlet weak var activityIndicator: UIActivityIndicatorView!
    
    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 : AddressListDM){
        self.addressName.text = data.addressName
        let address = data.address ?? ""
        let city = data.city ?? ""
        let state = data.state ?? ""
        let pincode = data.pincode ?? ""
        self.addressLine.text = address + city + state + ",\n" + pincode
        self.phoneNo.text = "Phone No. : " + (data.phoneNo ?? "+0")
        
        if let defaults = data.isDefault, defaults{
            self.radioImage.image = UIImage(named: "RadioOn")
            self.expecteDelivery.text = ""
            if let eddDate = data.eddDate{
                self.expecteDelivery.text = "Expected Delivery by" + "\n" + eddDate
            }
        }else{
            self.radioImage.image = UIImage(named: "RadioOff")
            self.expecteDelivery.text = ""
        }
        
        if let isAnimating = data.isAnimating{
            if isAnimating{
                activityIndicator.startAnimating()
            }else{
                activityIndicator.stopAnimating()
            }
        }
    }
}
