//
//  GroupAddParticipantsCell.swift
//  WoWonder
//
//  Created by Mac on 16/11/22.
//  Copyright © 2022 ScriptSun. All rights reserved.
//

import UIKit
import SDWebImage

protocol GroupAddParticipantsCellDelegate {
    func handleDeleteParticipant(indexPath: IndexPath)
}

class GroupAddParticipantsCell: UITableViewCell {
    
    @IBOutlet weak var cellView: UIView!
    @IBOutlet weak var userImageView: UIImageView!
    @IBOutlet weak var userNameLabel: UILabel!
    @IBOutlet weak var aboutLabel: UILabel!
    @IBOutlet weak var cancelButton: UIButton!
    
    var indexPath = IndexPath()
    var delegate: GroupAddParticipantsCellDelegate?
    
    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
    }
    
    // Set Data
    func setData(object: UserData) {
        self.userNameLabel.text = object.name ?? ""
        if object.about == "" {
            self.aboutLabel.text = "Hi there i am using WoWonder Messanger"
        } else {
            self.aboutLabel.text = object.about
        }
        let imageUrl = URL.init(string: object.avatar ?? "")
        let indicator = SDWebImageActivityIndicator.medium
        self.userImageView.sd_imageIndicator = indicator
        DispatchQueue.global(qos: .userInteractive).async {
            self.userImageView.sd_setImage(with: imageUrl, placeholderImage: UIImage(named: ""))
        }
    }
    
    @IBAction func cancelButtonAction(_ sender: UIButton) {
        self.delegate?.handleDeleteParticipant(indexPath: self.indexPath)
    }
    
}
