//
//  FavouriteCell.swift
//  WOKA
//
//  Created by MacBook Pro on 13/06/24.
//

import UIKit

enum FavCellCLick{
    case favourite
    case liked
}

class FavouriteCell: UICollectionViewCell {

    @IBOutlet weak var outerStack: UIStackView!
    @IBOutlet weak var cellImage: UIImageView!
    @IBOutlet weak var cellTitle: UILabel!
    @IBOutlet weak var likeBtn: UIButton!
    @IBOutlet weak var favBtnn: UIButton!
    @IBOutlet weak var totalLikes: UILabel!
    
    typealias btnTappedBlock = ( _ from : FavCellCLick) -> Void  // 0 - plus 1 - minus
    var btnTapped : btnTappedBlock!
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
    
    override func prepareForReuse() {
        super.prepareForReuse()
        // Reset or reapply shadow only if needed
        outerStack.layer.shadowPath = nil
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        outerStack.addShadowAndCorner(radius: 10, shadowColor: .darkGray, shadowOpacity: 0.6, shadowOffset: CGSize(width: 0, height: 0.5), shadowRadius: 5)
    }

    @IBAction func favouriteBtnTapped(_ sender: UIButton) {
        if btnTapped != nil {
            btnTapped( .favourite)
        }
    }
    
    @IBAction func likeBtnTapped(_ sender: UIButton) {
        if btnTapped != nil {
            btnTapped( .liked)
        }
    }
    
    func setData(data : FavouriteListingDM.ResultData.ShowDatum){
        //heart.fill , heart , hand.thumbsup.fill , hand.thumbsup
        if AuthFunc.shareInstance.getDefaultLanguage() == .english{
            cellTitle.text = data.contentMoreDetails?.filter({$0.languageMasterID == 1}).first?.title
        }else{
            cellTitle.text = data.contentMoreDetails?.filter({$0.languageMasterID == 2}).first?.title
        }
        totalLikes.text = data.likesCount?.toString() ?? "0"

        if let url = data.thumbnailPath{
            cellImage.imageURL(url)
        }
        
        if let favourite = data.markAsFavourite{
            switch favourite{
            case true:
                favBtnn.setImage(UIImage(named: "FavouriteAdd"), for: .normal)
            case false:
                favBtnn.setImage(UIImage(named: "FavouriteRemove"), for: .normal)
            }
        }
        
        if let like = data.isLiked{
            switch like{
            case true:
                likeBtn.setImage(UIImage(named: "LikeAdd"), for: .normal)
            case false:
                likeBtn.setImage(UIImage(named: "LikeRemove"), for: .normal)
            }
        }
    }
    
    func setOtherData(data : FavouriteListingDM.ResultData.Datum){
        //heart.fill , heart , hand.thumbsup.fill , hand.thumbsup
        if AuthFunc.shareInstance.getDefaultLanguage() == .english{
            cellTitle.text = data.contentMoreDetails?.filter({$0.languageMasterID == 1}).first?.title
        }else{
            cellTitle.text = data.contentMoreDetails?.filter({$0.languageMasterID == 2}).first?.title
        }
        totalLikes.text = data.likesCount?.toString() ?? "0"
        if let url = data.thumbnailPath{
            cellImage.imageURL(url)
        }
        
        if let favourite = data.markAsFavourite{
            switch favourite{
            case true:
                favBtnn.setImage(UIImage(named: "FavouriteAdd"), for: .normal)
            case false:
                favBtnn.setImage(UIImage(named: "FavouriteRemove"), for: .normal)
            }
        }
        
        if let like = data.isLiked{
            switch like{
            case true:
                likeBtn.setImage(UIImage(named: "LikeAdd"), for: .normal)
            case false:
                likeBtn.setImage(UIImage(named: "LikeRemove"), for: .normal)
            }
        }
    }
    
    func setGameData(data : GamesListDM.GameDatum){
        //heart.fill , heart , hand.thumbsup.fill , hand.thumbsup
        if AuthFunc.shareInstance.getDefaultLanguage() == .english{
            cellTitle.text = data.contentMoreDetails?.filter({$0.languageMasterID == 1}).first?.title
        }else{
            cellTitle.text = data.contentMoreDetails?.filter({$0.languageMasterID == 2}).first?.title
        }
        totalLikes.text = data.likesCount?.toString() ?? "0"
        if let url = data.thumbnailPath{
            cellImage.imageURL(url)
        }
        
        if let favourite = data.markAsFavourite{
            switch favourite{
            case true:
                favBtnn.setImage(UIImage(named: "FavouriteAdd"), for: .normal)
            case false:
                favBtnn.setImage(UIImage(named: "FavouriteRemove"), for: .normal)
            }
        }
        
        if let like = data.isLiked{
            switch like{
            case true:
                likeBtn.setImage(UIImage(named: "LikeAdd"), for: .normal)
            case false:
                likeBtn.setImage(UIImage(named: "LikeRemove"), for: .normal)
            }
        }
    }
    
    func setKaraokeData(data : KaraokeListingDM.KaraokeDatum){
        //heart.fill , heart , hand.thumbsup.fill , hand.thumbsup
        if AuthFunc.shareInstance.getDefaultLanguage() == .english{
            cellTitle.text = data.contentMoreDetails?.filter({$0.languageMasterID == 1}).first?.title
        }else{
            cellTitle.text = data.contentMoreDetails?.filter({$0.languageMasterID == 2}).first?.title
        }
        totalLikes.text = data.likesCount?.toString() ?? "0"
        if let url = data.thumbnailPath{
            cellImage.imageURL(url)
        }
        
        if let favourite = data.markAsFavourite{
            switch favourite{
            case true:
                favBtnn.setImage(UIImage(named: "FavouriteAdd"), for: .normal)
            case false:
                favBtnn.setImage(UIImage(named: "FavouriteRemove"), for: .normal)
            }
        }
        
        if let like = data.isLiked{
            switch like{
            case true:
                likeBtn.setImage(UIImage(named: "LikeAdd"), for: .normal)
            case false:
                likeBtn.setImage(UIImage(named: "LikeRemove"), for: .normal)
            }
        }
    }
    
    func setAudioData(data : ListenAudioListingDM.AudioDatum){
        //heart.fill , heart , hand.thumbsup.fill , hand.thumbsup
        if AuthFunc.shareInstance.getDefaultLanguage() == .english{
            cellTitle.text = data.contentMoreDetails?.filter({$0.languageMasterID == 1}).first?.title
        }else{
            cellTitle.text = data.contentMoreDetails?.filter({$0.languageMasterID == 2}).first?.title
        }
        totalLikes.text = data.likesCount?.toString() ?? "0"
        if let url = data.thumbnailPath{
            cellImage.imageURL(url)
        }
        
        if let favourite = data.markAsFavourite{
            switch favourite{
            case true:
                favBtnn.setImage(UIImage(named: "FavouriteAdd"), for: .normal)
            case false:
                favBtnn.setImage(UIImage(named: "FavouriteRemove"), for: .normal)
            }
        }
        
        if let like = data.isLiked{
            switch like{
            case true:
                likeBtn.setImage(UIImage(named: "LikeAdd"), for: .normal)
            case false:
                likeBtn.setImage(UIImage(named: "LikeRemove"), for: .normal)
            }
        }
    }
}
