//
//  SymbolSetViewController.m
//  Writing Tablet Jr
//
//  Created by Sean Campbell on 12/11/13.
//  Copyright (c) 2013 Sean Campbell. All rights reserved.
//

#import "SymbolSetViewController.h"

@implementation SymbolSetViewController

@synthesize symbols;
@synthesize symbolSet;
@synthesize drawCtrl;

- (id) init
{
    if (self = [super init]) {
        UIBarButtonItem *playSetItem = [[UIBarButtonItem alloc] init];
        playSetItem.title = @"Play Set";
        playSetItem.target = self;
        playSetItem.action = @selector(playSet);
        self.navigationItem.rightBarButtonItem = playSetItem;
        playSetItem = nil;
    }
    return self;
}

- (void) viewWillAppear:(BOOL)animated
{
    self.navigationItem.title = symbolSet;
    [self.tableView reloadData];
}

- (void) playSet
{
    drawCtrl.symbols = symbols;
    drawCtrl.symbolIndex = 0;
    drawCtrl.isAdvancing = YES;
    drawCtrl.symbolSet = self.symbolSet;
    drawCtrl.cumScore = 0;
    drawCtrl.cumTimeElapsed = 0;
    drawCtrl.cumAccuracy = 0;

    [self.navigationController pushViewController: drawCtrl animated: YES];
}

#pragma mark Table view methods

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

- (NSInteger) tableView: (UITableView *) tableView numberOfRowsInSection: (NSInteger) section
{
    return symbols.count;
}


- (BOOL) tableView: (UITableView *) tableView canEditRowAtIndexPath: (NSIndexPath *) indexPath
{
    return NO;
}

- (UITableViewCell *) tableView: (UITableView *) tableView cellForRowAtIndexPath: (NSIndexPath *) indexPath
{
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier];
    if (cell == nil)
        cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier: CellIdentifier];
    cell.textLabel.text = [NSString stringWithFormat:@"  %@", [symbols objectAtIndex: indexPath.row]];
    cell.textLabel.font = [UIFont fontWithName:@"Arial" size:14];
    
    /*
     cell.textLabel.font = [UIFont fontWithName: @"Helvetica-Bold" size: 14];
     cell.textLabel.textColor = [UIColor blueColor];
     cell.textLabel.highlightedTextColor = [UIColor yellowColor];
     cell.imageView.image = [UIImage imageNamed: @"4seasons.png"];
     */
    return cell;
}

- (void) tableView: (UITableView *) tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath
{
    drawCtrl.symbols = symbols;
    drawCtrl.symbolIndex = indexPath.row;
    drawCtrl.isAdvancing = NO;
    drawCtrl.symbolSet = self.symbolSet;
    [self.navigationController pushViewController: drawCtrl animated: YES];
}

@end
