//
//  SelectAvatarCell.swift
//  WOKA
//
//  Created by MacBook Pro on 02/05/24.
//

import UIKit

class SelectAvatarCell: UICollectionViewCell {

    @IBOutlet weak var outerView: UIView!
    @IBOutlet weak var imageView: UIImageView!
    
    override func awakeFromNib() {
        super.awakeFromNib()
        self.outerView.backgroundColor = UIColor.white.withAlphaComponent(0.5)
    }
    
    override func layoutSubviews() {
        self.roundCorner()
    }
    
    func setData(data : AvatarDM.ResultRecords){
        /*
         Reset the cells
         */
        self.outerView.backgroundColor = UIColor.white.withAlphaComponent(0.5)

        if data.avatarName == AuthFunc.shareInstance.regData.avtar{
            // Provide haptic feedback
            let selectionFeedback = UISelectionFeedbackGenerator()
            selectionFeedback.selectionChanged()
            UIView.animate(withDuration: 0.1, animations: { [weak self] in
                guard let self else{return}
                imageView.transform = CGAffineTransform(scaleX: 0.9, y: 0.9)
            }) { _ in
                UIView.animate(withDuration: 0.1) { [weak self] in
                    guard let self else{return}
                    imageView.transform = .identity
                    outerView.backgroundColor = .white
                }
            }
        }else{
            self.outerView.backgroundColor = UIColor.white.withAlphaComponent(0.5)
        }
        
        if let url = data.avatarImageURL{
            self.imageView.imageURL(url)
        }
    }
}
