//
//  GlobalSettings.m
//  iPhly
//
//  Created by Ari Krupnik on 6/23/11.
//  Copyright 2011 lib.aero. All rights reserved.
//

#import "GlobalSettingsViewController.h"
#import "MMSlider.h"

enum sections {
    PITCH_SENSITIVITY,
    ROLL_SENSITIVITY,
    TOUCH_X_SENSITIVITY,
    TOUCH_Y_SENSITIVITY,
    NUM_SECTIONS
};

@implementation GlobalSettingsViewController

- (id)initWithStyle:(UITableViewStyle)style {
    self = [super initWithStyle:UITableViewStyleGrouped];
    if (self) {
        [self setTitle:@"iPhly Config"];
        dataSource = [[ArrayTableDataSource alloc] init];
        NSMutableArray* sections = [NSMutableArray array];
        
        UITableSection* s = [[[UITableSection alloc]init]autorelease];
        [s setHeaderTitle:@"Accelerometer"];
        NSMutableArray* cells = [NSMutableArray array];
        MMTableCell* c = [[[MMTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil] autorelease];
        [[c textLabel] setText:@"Pitch Axis Limits"];
        [cells addObject:c];
        c = [[[MMTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil] autorelease];
        [[c textLabel] setText:@"Roll Axis Limits"];
        [cells addObject:c];
        [s setCells:cells];
        [sections addObject:s];
        
        s = [[[UITableSection alloc]init]autorelease];
        [s setHeaderTitle:@"Touchscreen"];
        cells = [NSMutableArray array];
        c = [[[MMTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil] autorelease];
        [[c textLabel] setText:@"Swipe Sensitivity"];
        [cells addObject:c];
        c = [[[MMTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil] autorelease];
        [[c textLabel] setText:@"Return Spring Tension"];
        [cells addObject:c];
        [s setCells:cells];
        [sections addObject:s];
        
        [dataSource setSections:sections];
        [[self tableView] setDataSource:dataSource];
    }
    return self;
}

- (void)dealloc {
    [dataSource release];
    [super dealloc];
}

#pragma mark - View lifecycle

#pragma mark - Table view data source

#pragma mark - Table view delegate

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell* c=[self.tableView.dataSource tableView:tableView cellForRowAtIndexPath:indexPath];
    if ([c isKindOfClass:[MMTableCell class]]) {
        return [(MMTableCell*) c height];
    } else {
        return 44;
    }
}

@end
