//
//  OnTapViewController.swift
//  BTap
//
//  Created by Chris Ki on 3/17/15.
//  Copyright (c) 2015 Jennifer Wang. All rights reserved.
//

import UIKit

//UITableViewDataSource,

class OnTapViewController: UIViewController,  UITableViewDelegate {

    @IBOutlet weak var beerlist: UITableView!
    
    var arrayOfonTaps: [onTap] = [onTap]()
    
    @IBOutlet weak var barlist: UITableView!
    @IBOutlet weak var segmented: UISegmentedControl!
    

    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.showBeers()
        

        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    
    func showBeers() {
        var beer1 = onTap(beername: "xbuzz", beerDescription: "icy blue")
        var beer2 = onTap(beername: "rocky mountain", beerDescription: "crimson red")
        var beer3 = onTap(beername: "bass", beerDescription: "aqua green")
        
        
        arrayOfonTaps.append(beer1)
        arrayOfonTaps.append(beer2)
        arrayOfonTaps.append(beer3)
    }
    
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return arrayOfonTaps.count
    }
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
            let cell: onTapcell = tableView.dequeueReusableCellWithIdentifier("BeerCell") as onTapcell
            let beer = arrayOfonTaps[indexPath.row]
            // check out Beer.swift and BeerListCell.swift for correct variable names
            cell.setCell(beer.beername)
            
            return cell
        }
    
    
        
    @IBAction func segmentvalue(sender: AnyObject) {
        
        if segmented.selectedSegmentIndex == 0 {
            self.beerlist.hidden == false;
            self.barlist.hidden == true;
        }
        if segmented.selectedSegmentIndex == 1 {
            self.beerlist.hidden == true;
            self.barlist.hidden == false;
        }
    
    
        switch segmented.selectedSegmentIndex
        {
        case 0:
            var arrayOfonTaps: [onTap] = [onTap]()
            
            func showBeers() {
                var beer1 = onTap(beername: "xbuzz", beerDescription: "icy blue")
                var beer2 = onTap(beername: "rocky mountain", beerDescription: "crimson red")
                var beer3 = onTap(beername: "bass", beerDescription: "aqua green")
                arrayOfonTaps.append(beer1)
                arrayOfonTaps.append(beer2)
                arrayOfonTaps.append(beer3)
            }
            
            func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
                return arrayOfonTaps.count
            };
            
        case 1:
            var arrayOfonTaps: [onTap] = [onTap]()
            func showBeers() {
                var beer1 = onTap(beername: "xbuzz", beerDescription: "icy blue")
                var beer2 = onTap(beername: "rocky mountain", beerDescription: "crimson red")
                var beer3 = onTap(beername: "bass", beerDescription: "aqua green")
                arrayOfonTaps.append(beer1)
                arrayOfonTaps.append(beer2)
                arrayOfonTaps.append(beer3)
            }
            
            func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
                return arrayOfonTaps.count
            };
        default:
            break;
            
        }
    }
    
    @IBAction func backButtonTapped(sender: AnyObject) {
        self.performSegueWithIdentifier("onTapToHome", sender: self);
        
        self.dismissViewControllerAnimated(true, completion: nil);
    }

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
