//
//  QuickResponseViewController.m
//  NG911
//
//  Created by Mason Silber on 12/5/11.
//  Copyright (c) 2011 Columbia University. All rights reserved.
//

#import "QuickResponseViewController.h"

@implementation QuickResponseViewController
@synthesize police, fire, medical, cancel, myDelegate;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) 
    {
        [[self view] setBackgroundColor:[UIColor underPageBackgroundColor]];
        UILabel *description = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 300, 150)];
        [description setText:@"Warning: Pressing these buttons will send an emergency request to a call taker at a 911 response center. Immediate help will be sent. Press cancel to go back to chat."];
        [description setFont:[UIFont systemFontOfSize:18]];
        [description setLineBreakMode:UILineBreakModeWordWrap];
        [description setNumberOfLines:0];
        [description setBackgroundColor:[UIColor clearColor]];
        [[self view] addSubview:description];
        [description release];
        
        police = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        [police setBackgroundImage:[UIImage imageNamed:@"Police.png"] forState:UIControlStateNormal];
        [police setFrame:CGRectMake(30, 210, 80, 80)];
        [police addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
        
        fire = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        [fire setBackgroundImage:[UIImage imageNamed:@"Fire.png"] forState:UIControlStateNormal];
        [fire setFrame:CGRectMake(120, 210, 80, 80)];
        [fire addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];

        medical = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        [medical setBackgroundImage:[UIImage imageNamed:@"Medical.png"] forState:UIControlStateNormal];
        [medical setFrame:CGRectMake(210, 210, 80, 80)];
        [medical addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];

        cancel = [UIButton buttonWithType:UIButtonTypeCustom];
        [cancel setBackgroundImage:[UIImage imageNamed:@"Cancel.png"] forState:UIControlStateNormal];
        [cancel setFrame:CGRectMake(33, 330, 254, 44)];
        [cancel addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
        
        [[self view] addSubview:police];
        [[self view] addSubview:fire];
        [[self view] addSubview:medical];
        [[self view] addSubview:cancel];
    }
    
    return self;
}

- (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.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

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

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

-(void)buttonPressed:(id)sender
{
    if(sender == police)
    {
        [[self myDelegate] quickResponseDismissed:@"Police"];
    }
    else if(sender == fire)
    {
        [[self myDelegate] quickResponseDismissed:@"Fire"];
    }
    else if(sender == medical)
    {
        [[self myDelegate] quickResponseDismissed:@"Medical"];
    }
    else
    {
        [[self myDelegate] quickResponseDismissed:@"Cancel"];
    }
    [self dismissModalViewControllerAnimated:YES];
}

@end
