//
//  RootViewController.m
//  DVDCase
//
//  Created by Bill Dudney on 1/2/09.
//  Copyright Gala Factory Software LLC 2009. All rights reserved.
//
//
//  Licensed with the Apache 2.0 License
//  http://apache.org/licenses/LICENSE-2.0
//

#import "RootViewController.h"
#import "DVDCaseAppDelegate.h"
#import "DVDCabinetController.h"

@implementation RootViewController

@synthesize cabinetController;

//START:code.RVC.viewDidLoad
- (void)viewDidLoad {
  [super viewDidLoad];
  self.title = @"Cases";
}
//END:code.RVC.viewDidLoad

#pragma mark Table view methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}


//START:code.RVC.tvdata
- (NSInteger)tableView:(UITableView *)tableView
 numberOfRowsInSection:(NSInteger)section {
  return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  
  static NSString *CellIdentifier = @"Cell";
  
  UITableViewCell *cell = 
          [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  if (cell == nil) {
	  cell = [[[UITableViewCell alloc] initWithStyle:UITableViewStylePlain
                       reuseIdentifier:CellIdentifier] 
		autorelease];
  }
  
  cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  
  switch (indexPath.row) {
    case 0:
      cell.textLabel.text = @"Home";
      break;
    case 1:
      cell.textLabel.text = @"Work";
      break;
    default:
      break;
  }
  return cell;
}
//END:code.RVC.tvdata

//START:code.RVC.didSelectRowAtIndexPath
- (void)tableView:(UITableView *)tableView 
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  if(0 == indexPath.row) {
    self.cabinetController.key = @"home";
    self.cabinetController.title = @"Home";
  } else {
    self.cabinetController.key = @"work";
    self.cabinetController.title = @"Work";
  }
  [self.navigationController pushViewController:self.cabinetController
                                       animated:YES];
}
//END:code.RVC.didSelectRowAtIndexPath

- (void)dealloc {
  self.cabinetController = nil;
  [super dealloc];
}


@end

