//
//  ShopListingCell.swift
//  WOKA
//
//  Created by MacBook Pro on 22/07/24.
//

import UIKit

class ShopListingCell: UITableViewCell {

    @IBOutlet weak var cellImage: UIImageView!
    @IBOutlet weak var cellTitle: UILabel!
    @IBOutlet weak var shimmerEffectView: ShimmerEffectView!
    
    @IBOutlet weak var imageHeight: NSLayoutConstraint!
    
    override func prepareForReuse() {
        super.prepareForReuse()
        // Reset or reapply shadow only if needed
        shimmerEffectView.layer.shadowPath = nil
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        self.backgroundColor = .clear
        shimmerEffectView.addShadowAndCorner(radius: 8, shadowColor: .darkGray, shadowOpacity: 0.6, shadowOffset: CGSize(width: 0, height: 0.5), shadowRadius: 5)
    }
    
    func showShimmer(){
        shimmerEffectView.gradientColorOne = #colorLiteral(red: 0.4969186187, green: 0.8725844026, blue: 1, alpha: 1)
        shimmerEffectView.gradientColorTwo = #colorLiteral(red: 0.9254901961, green: 0.9254901961, blue: 0.9254901961, alpha: 1)
        shimmerEffectView.startShimmer()
    }
    
    func stopShimmer(){
        shimmerEffectView.stopShimmer()
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
    }
    
    func setData(data : ShopSuperCategoryDM.ResultData){
        
        if data.isAD == true{
            self.cellImage.contentMode = .scaleAspectFit
            self.imageHeight.constant = self.cellImage.frame.width * 0.55
        }else{
            self.imageHeight.constant = 180
            self.cellImage.contentMode = .scaleAspectFill
        }
        
        if let url = data.superCategoryThumbnail{
            self.cellImage.imageURL(url, color: .black)
        }
        self.cellTitle.text = data.superCategoryName
        self.layoutIfNeeded()
    }
    
    func setCategoryData(data : ShopCategoryDM.ResultData){
        if let url = data.categoryThumbnail{
            self.cellImage.imageURL(url, color: .black)
        }
        self.cellTitle.text = data.categoryName
    }
}
