//
//  FavouritesVC.swift
//  Garmentoo
//
//  Created by Vijith on 30/03/22.
//

import UIKit

class FavouritesVC: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

       
    }
    

    
   

}
extension FavouritesVC: UITableViewDelegate,UITableViewDataSource
{
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 5
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "favCell", for: indexPath) as! FavTableViewCell
        return cell
    }
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 140
    }
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let sb = UIStoryboard(name: "Main", bundle: nil)
        let nextVc = sb.instantiateViewController(withIdentifier: "ProductDetailVC") as! ProductDetailVC
        nextVc.hidesBottomBarWhenPushed = true
        self.navigationController?.pushViewController(nextVc, animated: true)
    }
    
    
}

// for hiding tabbar when scrolls
extension FavouritesVC:UIScrollViewDelegate{
    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        if scrollView.panGestureRecognizer.translation(in: scrollView).y < 0{
            //scrolling down
            //self.scrollBottomConstraint.constant = 0
            changeTabBar(hidden: true, animated: true)
        }
        else{
            //scrolling up
           // self.scrollBottomConstraint.constant = 20
            changeTabBar(hidden: false, animated: true)
        }
    }
    
    func changeTabBar(hidden:Bool, animated: Bool){
           let tabBar = self.tabBarController?.tabBar
           let offset = (hidden ? UIScreen.main.bounds.size.height : UIScreen.main.bounds.size.height - (tabBar?.frame.size.height)! )
           if offset == tabBar?.frame.origin.y {return}
           print("changing origin y position")
           let duration:TimeInterval = (animated ? 0.5 : 0.0)
           UIView.animate(withDuration: duration,
                          animations: {tabBar!.frame.origin.y = offset},
                          completion:nil)
       }
}
