 import AFNetworking
 import MBProgressHUD
 import SwiftyJSON
+import Alamofire
+import AlamofireImage
 
 class MoviesViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UICollectionViewDataSource, UICollectionViewDelegate, UISearchBarDelegate {
     

    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        selectedMovie = self.filteredMovies[indexPath.row]
        performSegue(withIdentifier: "showDetail", sender: self)
    }
    

    
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        selectedMovie = self.filteredMovies[indexPath.row]
        // set background for navbar
        let imgUrl = posterBaseUrl + (selectedMovie["poster_path"] as? String)!
        Alamofire.request(imgUrl, method: .get).responseImage { response in
            guard let image = response.result.value else {
                // Handle error
                return
            }
            self.navigationController?.navigationBar.setBackgroundImage(image, for: UIBarMetrics.default)
        }
        performSegue(withIdentifier: "showDetail", sender: self)
    }
    
