//
//  LinkedChildCell.swift
//  WOKA
//
//  Created by MacBook Pro on 09/05/24.
//

import UIKit

class LinkedChildCell: UITableViewCell {

    @IBOutlet weak var outerView: UIView!
    @IBOutlet weak var childAvatarImage: UIImageView!
    @IBOutlet weak var childName: UILabel!
    @IBOutlet weak var imageSupportView: UIView!
    
    override func awakeFromNib() {
        super.awakeFromNib()
        outerView.roundCorner(radius: 15)
        outerView.backgroundColor = .white.withAlphaComponent(0.5)
    }

    override func layoutSubviews() {
        imageSupportView.roundCorner()
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    func setData(data : LinkedChildDM.ResultChild){
        if let imageAvatar = data.avtar{
            self.childAvatarImage.imageURL(imageAvatar)
        }
        self.childName.text = data.username
    }
    
    func setLinkedData(data : UserNameDM){
        self.childName.text = data.username
        self.childAvatarImage.image = UIImage(named: "DefaultAvatar")
        if data.isSelected == true{
            ViewButtonAnimation.sharedInstance.cellTapped(view: self.outerView) { [weak self] in
                guard let self else{return}
                outerView.backgroundColor = #colorLiteral(red: 0.368627451, green: 0.1215686275, blue: 0.768627451, alpha: 1)
                childName.textColor = .white
            }
            
        }else{
            outerView.backgroundColor = .white.withAlphaComponent(0.5)
            childName.textColor = UIColor.appColor(.TextDarkBlue)
        }
    }
}
