             } else {
                 autocompleteTableView.isHidden = false
             }
-        }
-    }
+            updateSortFilterHiddentState()
+        }
+    }
+
     var searchTerm = "" {
         didSet {
             if searchTerm.isEmpty {
                 products.removeAll()
                 autocompleteSuggestions.removeAll()
+                pageCount = 0
             }
             else {
                 searchBar.text = searchTerm
-            }
-        }
+                searchProductsView.isHidden = true
+            }
+        }
+    }
+
+    func updateSortFilterHiddentState() {
+        sortFilterView.isHidden = products.isEmpty || autocompleteTableView.isHidden == false
+    }
+
+    func updateSearchProductsView() {
+        searchProductsView.isHidden = !products.isEmpty
+        searchProductsLabel.text = searchTerm.isEmpty ? "Search Products" : "No Results"
+        searchProductsImageView.image = UIImage(named: searchTerm.isEmpty ? "img-search.pdf" : "img-noresults.pdf")
     }
 }
 

            searchResultsCollectionView.reloadData()
            if products.isEmpty {
                searchResultsCollectionView.isHidden = true
                searchProductsView.isHidden = false
                searchProductsLabel.text = "No Results"
                searchProductsImageView.image = UIImage(named: "img-noresults.pdf")
            } else {
                searchResultsCollectionView.isHidden = false
                searchProductsView.isHidden = true
            }
        }
    }
    var autocompleteSuggestions: [String] = [] {

    }
    
    func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
        searchTerm = searchText.replacingOccurrences(of: " ", with: "")
        timer?.invalidate()
        if !searchTerm.isEmpty {
            autocomplete(withQuery: searchText)
            timer = Timer.scheduledTimer(timeInterval: 0.5, target: self, selector: #selector(self.searchForProducts), userInfo: nil, repeats: false)
        }
    }
    
