//
//  DoubleComponentPickerViewController.m
//  Pickers
//
//  Created by jeff on 4/17/09.
//  Copyright 2009 Jeff LaMarche. All rights reserved.
//

#import "DoubleComponentPickerViewController.h"

@implementation DoubleComponentPickerViewController
@synthesize doublePicker;
@synthesize fillingTypes;
@synthesize breadTypes;
-(IBAction)buttonPressed:(id)sender
{
    NSInteger breadRow = [doublePicker selectedRowInComponent:
                          kBreadComponent];
    NSInteger fillingRow = [doublePicker selectedRowInComponent:
                            kFillingComponent];
    
    NSString *bread = [breadTypes objectAtIndex:breadRow];
    NSString *filling = [fillingTypes objectAtIndex:fillingRow];
    
    NSString *message = [[NSString alloc] initWithFormat:
                         @"Vase napln %@ v %@ chlebu bude hned hotova.", filling, bread];
    
    
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:
                          @"Dekujeme za objednavku" 
                                                    message:message 
                                                   delegate:nil 
                                          cancelButtonTitle:@"Vyborne!" 
                                          otherButtonTitles:nil];
    [alert show];
    [alert release];
    [message release];
    
}
- (void)viewDidLoad {
    NSArray *breadArray = [[NSArray alloc] initWithObjects:@"Bilem", 
                           @"Psenicnem", @"Zitnem", @"Kvaskovem", @"Vicezrnnem", nil];
    self.breadTypes = breadArray;
    [breadArray release];
    
    NSArray *fillingArray = [[NSArray alloc] initWithObjects:@"Sunka", 
                             @"Kruta", @"Burakove maslo", @"Tunakovy salat", 
                             @"Kureci salat", @"Hovezi pecene", @"Pomazanka", nil];
    self.fillingTypes = fillingArray;
    [fillingArray release];
}

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
    self.doublePicker = nil;
    self.breadTypes = nil;
    self.fillingTypes = nil;
    [super viewDidUnload];
}

- (void)dealloc {
    [doublePicker release];
    [breadTypes release];
    [fillingTypes release];
    [super dealloc];
}
#pragma mark -
#pragma mark Picker Data Source Methods
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 2;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView  
numberOfRowsInComponent:(NSInteger)component
{
    if (component == kBreadComponent)
        return [self.breadTypes count];
    
    return [self.fillingTypes count];
}
#pragma mark Picker Delegate Methods
- (NSString *)pickerView:(UIPickerView *)pickerView 
             titleForRow:(NSInteger)row 
            forComponent:(NSInteger)component
{
    if (component == kBreadComponent)
        return [self.breadTypes objectAtIndex:row];
    
    return [self.fillingTypes objectAtIndex:row];
}
@end
