//
//  ViewController.m
//  MedicalHelp
//
//  Created by mac on 6/24/14.
//  Copyright (c) 2014 mac. All rights reserved.
//

#import "MainViewController.h"

@implementation MainViewController

@synthesize arrayMainMenu,arrayMainMenuDetail,tblTableView;

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    
    arrayMainMenu = [[NSArray alloc]initWithObjects:@"Symptom Checker",@"Search Medical Drugs",@"Search Medical Center", @"First Aid Treatment" ,@"Diet" ,@"About", nil];
    
    arrayMainMenuDetail = [[NSArray alloc]initWithObjects:@"Provide Information About Symptoms and its Possible Conditions",@"Get Information about Medical Drug",@"Use Map to Search Nearest Medical Centre", @"Provide Information about First Aid Treatment" ,@"Provide Information about Various Diet" ,@"About Medical Help Apps", nil];
    
    [self.navigationItem setTitle:@"Medical Help"];
    
   // self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"wallpaper1.png"]];
    
    UIImageView *tempImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"wallpaper1.png"]];
    [tempImageView setFrame:self.tblTableView.frame];
    self.tblTableView.backgroundView = tempImageView;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellId = @"CellDefaultId001";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellId];
    }
    
    cell.textLabel.text = [arrayMainMenu objectAtIndex:indexPath.row];
    
    cell.detailTextLabel.text = [arrayMainMenuDetail objectAtIndex:indexPath.row];
    
    switch (indexPath.row) {
        case 0:
            cell.imageView.image = [UIImage imageNamed:@"SymptomChecker.png"];
            break;
        case 1:
            cell.imageView.image = [UIImage imageNamed:@"MedicalDrug.png"];
            break;
        case 2:
            cell.imageView.image = [UIImage imageNamed:@"PlaceSearch.png"];
            break;
        case 3:
            cell.imageView.image = [UIImage imageNamed:@"PlusIcon.png"];
            break;
        case 4:
            cell.imageView.image = [UIImage imageNamed:@"Diet.png"];
            break;
        case 5:
            cell.imageView.image = [UIImage imageNamed:@"about.png"];
            break;
        default:
            break;
    }
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.row) {
        case 0:
        {
            if ([self isInternetConnected]) {
                SymCheckerBPViewController *v1 = [[SymCheckerBPViewController alloc]init];
                [self.navigationController pushViewController:v1 animated:YES];
            }
            else
            {
                [self showInternetNotConnectedWarning];
            }
            
            break;
        }
        case 1:
        {
            if ([self isInternetConnected]) {
                
                SearchMedicalDrugViewController *v1 = [[SearchMedicalDrugViewController alloc]init];
                
                [self.navigationController pushViewController:v1 animated:YES];
            }
            else
            {
                [self showInternetNotConnectedWarning];
            }
            break;
        }
        case 2:
        {
            if ([self isInternetConnected]) {
                SearchMedicalCentreViewController *v1 = [[SearchMedicalCentreViewController alloc]init];
                [self.navigationController pushViewController:v1 animated:YES];
            }
            else
            {
                [self showInternetNotConnectedWarning];
            }
            break;
        }
        case 3:
        {
            FirstAidTableViewController *v1 = [[FirstAidTableViewController alloc]init];
            
            [self.navigationController pushViewController:v1 animated:YES];
            
            break;
        }
        case 4:
        {
            DietViewController *v1 = [[DietViewController alloc]init];
            
            [self.navigationController pushViewController:v1 animated:YES];
            break;
        }
        case 5:
        {
            AboutViewController *v1 = [[AboutViewController alloc]init];
            v1.modalPresentationStyle = UIModalPresentationCurrentContext;
            
            [self presentViewController:v1 animated:YES completion:nil];
            //[self.navigationController pushViewController:v1 animated:YES];
            
            break;
        }
        default:
            break;
    }
}

//CHECK FOR INTERNET CONNECTION
-(BOOL)isInternetConnected
{
    Reachability *reachability = [Reachability reachabilityForInternetConnection];
    NetworkStatus networkStatus = [reachability currentReachabilityStatus];
    return networkStatus != NotReachable;
}

-(void)showInternetNotConnectedWarning
{
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Error" message:@"Internet Connection Required" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
    
    [alert show];
}

@end

