//
//  MyListViewAllCell.swift
//  WOKA
//
//  Created by MacBook Pro on 08/08/24.
//

import UIKit

class MyListViewAllCell: UITableViewCell {

    @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()
        self.backgroundColor = .clear
        // Initialization code
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    @IBAction func favouriteBtnTapped(_ sender: UIButton) {
        if btnTapped != nil {
            btnTapped( .favourite)
        }
    }
    
    @IBAction func likeBtnTapped(_ sender: UIButton) {
        if btnTapped != nil {
            btnTapped( .liked)
        }
    }

    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 audioData(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)
            }
        }
    }
    func gameData(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 webSeriesData(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)
            }
        }
    }
    
}
