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

#import "SymCheckerSBPViewController.h"

@implementation SymCheckerSBPViewController

@synthesize arraypkSBPid,arraySBP,arrayTblSBP,lblSBPName,indexSBP,imgSBPimage,arrayfkBPid,indexfkBP,strBPName,indexpkSBPid,indexSBPImage;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    RequestHandler *req = [[RequestHandler alloc]init];
    
    //Fire query and
    //Recieve Whole table in Array -->Dictonary
    arrayTblSBP = [[NSMutableArray alloc]initWithArray:[req getList:[NSString stringWithFormat:@"select * from tblsubbodypart where fkBPid = %d",indexfkBP]]];
    
    
    //Setup array Each Array Resepresented One Column of Table
    arraypkSBPid  = [[NSMutableArray alloc]init];
    arraySBP = [[NSMutableArray alloc]init];
    arrayfkBPid = [[NSMutableArray alloc]init];

    
    //Convert Individual Array.Each Array Resepresented One Column of Table
    for (NSDictionary *dict in arrayTblSBP) {
        [arraypkSBPid addObject:[dict objectForKey:@"pkSBPid"]];
        [arraySBP addObject:[dict objectForKey:@"SubBodyPart"]];
        [arrayfkBPid addObject:[dict objectForKey:@"fkBPid"]];
    }
    
    //This is used for left and right button and swiping gestures.
    indexSBP = 0;
    
    
    //add image to array
    
    indexSBPImage = [[NSMutableArray alloc]initWithObjects:@"SBPScalp.jpg",@"SBPEye.jpg",@"SBPNose.jpg",@"SBPFace.jpg",@"SBPMouth.jpg",@"SBPJaw.jpg",@"SBPEar.jpg",@"SBPNeck(Front).jpg",@"SBPNeck(Back).jpg",@"SBPChest.jpg",@"SBPLateralChest.jpg",@"SBPSternum.jpg",@"SBPUpperAbdomen.jpg",@"SBPLowerAbdomen.jpg",@"SBPBack.jpg",@"SBPUpperSpine.jpg",@"SBPLowerSpine.jpg",@"SBPGroin.jpg",@"SBPPelvis.jpg",@"SBPGenitals.jpg",@"SBPHip.jpg",@"SBPButtock.jpg",@"SBPThigh.jpg",@"SBPKnee.jpg",@"SBPShin.jpg",@"SBPAnkle.jpg",@"SBPFoot.jpg",@"SBPToes.jpg",@"SBPHamstring.jpg",@"SBPKnee(Back).jpg",@"SBPCalf.jpg",@"SBPSole.jpg",@"SBPShoulder.jpg",@"SBPUpper Arm (bicep).jpg",@"SBPUpper Arm (tricep).jpg",@"SBPArmpit.jpg",@"SBPElbow.jpg",@"SBPForearm (flexor).jpg",@"SBPWrist.jpg",@"SBPPalm.jpg",@"SBPFingers.jpg", nil];

    
    //This is used to forwarding SBPid
    indexpkSBPid = [[arraypkSBPid objectAtIndex:0] integerValue];
    
    //Set initial image
    imgSBPimage.image = [UIImage imageNamed:[indexSBPImage objectAtIndex:indexpkSBPid-1]];
    
    //add first Subbody part in to lable and image (In the format Index.SubBodyPart example: 1.nose ...)
    lblSBPName.text = [NSString stringWithFormat:@"%d.%@",indexSBP+1,[arraySBP objectAtIndex:indexSBP]];
    
    //Add bar button item to top
    UIBarButtonItem *btnHome = [[UIBarButtonItem alloc]initWithTitle:@"Home" style:UIBarButtonItemStyleBordered target:self action:@selector(goHome)];
    
    [self.navigationItem setRightBarButtonItem:btnHome];
    
    //and set title
    [self.navigationItem setTitle:strBPName];
    
    //Add Background
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"wallpaper1.png"]];
    
}

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

- (IBAction)btnBackword:(id)sender
{
    if (indexSBP == 0) {
        indexSBP = arraySBP.count - 1;
        indexpkSBPid = [[arraypkSBPid objectAtIndex:arrayfkBPid.count-1] integerValue];
    }
    else
    {
        indexSBP--;
        indexpkSBPid--;
    }
    imgSBPimage.image = [UIImage imageNamed:[indexSBPImage objectAtIndex:indexpkSBPid-1]];

    lblSBPName.text = [NSString stringWithFormat:@"%d.%@",indexSBP+1,[arraySBP objectAtIndex:indexSBP]];
}

- (IBAction)btnForward:(id)sender
{
    if (indexSBP == arraySBP.count - 1) {
        indexSBP = 0;
        indexpkSBPid = [[arraypkSBPid objectAtIndex:0] integerValue];
    }
    else
    {
        indexSBP++;
        indexpkSBPid++;
    }
    
    imgSBPimage.image = [UIImage imageNamed:[indexSBPImage objectAtIndex:indexpkSBPid-1]];
    lblSBPName.text = [NSString stringWithFormat:@"%d.%@",indexSBP+1,[arraySBP objectAtIndex:indexSBP]];
}

- (IBAction)btnSBPNext:(id)sender {
    
    SymCheckerSymptomViewController *symptomViewController = [[SymCheckerSymptomViewController alloc]init];
    
    symptomViewController.indexfkSBP = indexpkSBPid;
    
    symptomViewController.strSBPName = lblSBPName.text;
    
    [self.navigationController pushViewController:symptomViewController animated:YES];
}

-(void)goHome
{
    [self.navigationController popToRootViewControllerAnimated:YES];
}
@end
