//
//  ToolsPanelViewController.m
//  Apex Mobile
//
//  Created by Ray on 14-4-17.
//  Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
//

#import "ToolsPanelViewController.h"

@interface ToolsPanelViewController ()

@end

@implementation ToolsPanelViewController

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

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}
-(void)initpanel
{
    self.toolsinfo = [[NSMutableArray alloc] init];
    
    NSMutableDictionary* map = [[NSMutableDictionary alloc] init];
    
    [map setValue:@"Market news" forKey:@"title"];
    [map setValue:@"rect_market_news" forKey:@"img"];
    [self.toolsinfo addObject:map.copy];
    
    [map setValue:@"Announcements" forKey:@"title"];
    [map setValue:@"rect_announcements" forKey:@"img"];
    [self.toolsinfo addObject:map.copy];
    NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
    bool autologin =[defaults boolForKey:@"autologin"];
    
    if(autologin)
    {
        
        [map setValue:@"Saved Detail/Search" forKey:@"title"];
        [map setValue:@"rect_search_history" forKey:@"img"];
        [self.toolsinfo addObject:map.copy];
        
        
        [map setValue:@"Change Password" forKey:@"title"];
        [map setValue:@"rect_change_password" forKey:@"img"];
        [self.toolsinfo addObject:map.copy];
        
//        [map setValue:@"Setting" forKey:@"title"];
//        [map setValue:@"rect_setting" forKey:@"img"];
//        [self.toolsinfo addObject:map.copy];
    }

    
    [map setValue:@"Apex History" forKey:@"title"];
    [map setValue:@"rect_history" forKey:@"img"];
    [self.toolsinfo addObject:map.copy];
    
    [map setValue:@"About this App" forKey:@"title"];
    [map setValue:@"rect_about" forKey:@"img"];
    [self.toolsinfo addObject:map.copy];
    
    
    //
    
}

- (void)viewDidLoad
{
    [super viewDidLoad];
  //

    
    [self initpanel];
    // Do any additional setup after loading the view.
}
- (void)viewWillAppear:(BOOL)animated
{
    if(self.showNavigation==false)
    [self.navigationController setNavigationBarHidden:true];
}
- (void)viewWillDisappear:(BOOL)animated
{
    if(self.showNavigation==false)
    [self.navigationController setNavigationBarHidden:false];
}

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

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
 {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return self.toolsinfo.count;
    
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    DebugLog(@"cellForRowAtIndexPath");
    
    NSString *CellIdentifier = @"tools";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    NSString* title = [self.toolsinfo[indexPath.row] valueForKey:@"title"];
    
    //    UIImageView* iv= [[UIImageView alloc] initWithImage:];
    cell.textLabel.text = title;
    cell.imageView.image = [UIImage imageNamed:[self.toolsinfo[indexPath.row] valueForKey:@"img"]];
    
    return cell;
    
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
//    SearchViewController *searchViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"NewsView"];
//    searchViewController.function_name = @"Download Document";
//    [self.navigationController pushViewController:searchViewController animated:YES];
//    return;
    
    NSString* title = [self.toolsinfo[indexPath.row] valueForKey:@"title"];
    if([title isEqualToString:@"Market news"])
    {
        NewsViewController *viewcontroller=[self.storyboard instantiateViewControllerWithIdentifier:@"NewsView"];
        viewcontroller.module_name = @"Market news";
        [self.navigationController pushViewController:viewcontroller animated:YES];
    }
    else if([title isEqualToString:@"Announcements"])
    {
        NewsViewController *viewcontroller=[self.storyboard instantiateViewControllerWithIdentifier:@"NewsView"];
        viewcontroller.module_name = @"Announcements";
        [self.navigationController pushViewController:viewcontroller animated:YES];
    }
    else if([title isEqualToString:@"Saved Detail/Search"])
    {
        
        HistoryTabBarController *viewcontroller=[[HistoryTabBarController alloc] init];
        
        [self.navigationController pushViewController:viewcontroller animated:YES];

    }
    else if([title isEqualToString:@"Change Password"])
    {
        ChangePasswordViewController *viewcontroller=[self.storyboard instantiateViewControllerWithIdentifier:@"ChangePassword"];
//        newsview.module_name = @"Market news";
        [self.navigationController pushViewController:viewcontroller animated:YES];
    }
//    else if([title isEqualToString:@"Setting"])
//    {
//        ChangePasswordViewController *newsview=[self.storyboard instantiateViewControllerWithIdentifier:@"Setting"];
////        newsview.module_name = @"Market news";
//        [self.navigationController pushViewController:newsview animated:YES];
//    }
    else if([title isEqualToString:@"Apex History"])
    {
         ApexHistoryViewController *viewcontroller=[self.storyboard instantiateViewControllerWithIdentifier:@"ApexHistory"];
//        newsview.module_name = @"Market news";
        [self.navigationController pushViewController:viewcontroller animated:YES];
    }
    else if([title isEqualToString:@"About this App"])
    {
        AboutViewController *viewcontroller=[self.storyboard instantiateViewControllerWithIdentifier:@"About"];
//        newsview.module_name = @"Market news";
        [self.navigationController pushViewController:viewcontroller animated:YES];
    }
}

@end
