 import UIKit
 import Alamofire;
 
-class ViewController: UIViewController , UITableViewDelegate, UITableViewDataSource, UISearchBarDelegate{
+class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource{
 
-    @IBOutlet weak var textbox: UITextField!
     @IBOutlet weak var tableView: UITableView!
-    @IBOutlet weak var searchBar: UISearchBar!
     
     // Cell Identifier
     let cellIdentifier = "TableCell"
     
-    // Keeping track if a search is active.
-    var searchActive: Bool = false
-    
     // Empty `Restaurant` Array
     var list:[Restaurant] = []
     
-    // Empty filtered `Restaurant` Array
-    var filtered:[Restaurant] = []
+    weak var selectedRetaurant: Restaurant!
+    var menuList:[Menu] = []
     
     // `viewDidLoad` function override.
     // Set `tableView` height. Registers its class.
     // Initiates a request to fetch restaurants from API.
     override func viewDidLoad() {
         super.viewDidLoad()
+        self.view.backgroundColor = Utils.UIColorFromRGB(0xC1272D)
+        self.view.tintColor = Utils.UIColorFromRGB(0xFFFFFF)
+        
         self.tableView.delegate = self
         self.tableView.dataSource = self
-        self.searchBar.delegate = self
+        
         self.tableView.rowHeight = UITableViewAutomaticDimension
         self.tableView.registerClass(TableCell.self, forCellReuseIdentifier: cellIdentifier)
         self.getTopRestaurants()

        });
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if self.searchActive {
            return self.filtered.count
        }
        return self.list.count
    }
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        var cell:UITableViewCell = self.tableView.dequeueReusableCellWithIdentifier(cellIdentifier) as! UITableViewCell
        let item: Restaurant;
        
        if self.searchActive {
            item = self.filtered[indexPath.row] as Restaurant
        }
        else {
            item = self.list[indexPath.row] as Restaurant
        }
        
        cell.textLabel?.text = item.getName()
        cell.detailTextLabel?.text = item.getType()
        cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator

    }
    
    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        let id = self.list[indexPath.row].getId();
        
        selectedRetaurant = self.list[indexPath.row]

        Request.getMenus(id, handler: {
            (menus, error) in
            if error == nil{
                if menus.count > 0 {
                    self.menuList = menus
                    self.performSegueWithIdentifier("menu_details_segue", sender: self)
                }
                else {
                    self.presentViewController(Alerts.somethingBroke(), animated: true, completion: nil)
                }
            }
        })
    }

}
