//
//  StoryReactionGifCell.swift
//  WoWonder
//
//  Created by iMac on 26/09/23.
//  Copyright © 2023 ScriptSun. All rights reserved.
//

import UIKit
import SDWebImage

protocol StoryReactionGifCellDelegate {
    func handleReactionButtonTap(_ sender: UIButton)
}

class StoryReactionGifCell: UICollectionViewCell {
    
    @IBOutlet weak var gifImageView: SDAnimatedImageView!
    @IBOutlet weak var reactionButton: UIButton!
    
    var delegate: StoryReactionGifCellDelegate?

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        
        
    }
    
    // Reaction Button Action
    @IBAction func reactionButtonAction(_ sender: UIButton) {
        self.performZoomAnimation()
        self.delegate?.handleReactionButtonTap(sender)
    }
    
    func performZoomAnimation() {
        UIView.animate(withDuration: 0.5, animations: {
            // Zoom in by increasing the scale
            self.gifImageView.transform = CGAffineTransform(scaleX: 1.5, y: 1.5)
        }) { (finished) in
            // After zoom-in animation is complete, zoom out
            UIView.animate(withDuration: 0.5, animations: {
                self.gifImageView.transform = CGAffineTransform.identity
            })
        }
    }
    
    func setReactionGif(gif: String) {
        if let gifURL = Bundle.main.url(forResource: gif, withExtension: "gif") {
            self.gifImageView.sd_setImage(with: gifURL)
        }
    }

}
