//
//  PlusViewController.m
//  Allzic
//
//  Created by Alia Bourouis on 24/03/14.
//  Copyright (c) 2014 Alia Bourouis. All rights reserved.
//

#import "PlusViewController.h"
#import "AppDelegate.h"

@interface PlusViewController ()

@end

@implementation PlusViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        [searchView removeFromSuperview];
        [dataTable setFrame:CGRectMake(0.0f, navigationView.frame.origin.y + navigationView.frame.size.height, appDelegate.screenBounds.size.width, appDelegate.screenBounds.size.height - navigationView.frame.origin.y - navigationView.frame.size.height - footerTabView.frame.size.height)];
        if (appDelegate.systemVersion < 7.0) {
           [dataTable setFrame:CGRectMake(0.0f, navigationView.frame.origin.y + navigationView.frame.size.height, appDelegate.screenBounds.size.width, appDelegate.screenBounds.size.height - navigationView.frame.origin.y - navigationView.frame.size.height - footerTabView.frame.size.height - 20.0f)];
        }
        [self displayBackView];
    }
    return self;
}

- (void)backToParentView {
    
    [appDelegate.window setRootViewController:appDelegate.introVC];
}


//-----------------------------------------
//		TableView Delegate
//-----------------------------------------

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    int nbSection = 1;
    return nbSection;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    int nbRowInSection = 5;
    return nbRowInSection;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *cellIdentifier = @"dataCell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    //if(cell == nil) {
    //NSLog(@"cell = nil");
    
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    
    UIView *background = [[UIView alloc]initWithFrame:CGRectMake(0.0f, 0.0f , tableView.frame.size.width,tableView.rowHeight)];
    if (indexPath.row % 2) {
        background.backgroundColor = [UIColor colorWithRed:232.0f/255.0f green:243.0f/255.0f blue:248.0f/248.0f alpha:1.0f];
    } else {
        background.backgroundColor = [UIColor whiteColor];
    }
    [cell.contentView addSubview:background];
    
    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(20.0f, 10.0f, tableView.frame.size.width - 30.0f, tableView.rowHeight - 20.0f)];
    [titleLabel setFont:[UIFont systemFontOfSize:16]];
    [titleLabel setNumberOfLines:0];
    [titleLabel setBackgroundColor:[UIColor clearColor]];
    [titleLabel setTextColor:[UIColor blackColor]];
    switch (indexPath.row) {
        case 0: {
            [titleLabel setText:@"Site web Allzic"];
        }
            break;
        case 1: {
            [titleLabel setText:@"Page Facebook"];
        }
            break;
        case 2: {
            [titleLabel setText:@"Page Twitter"];
        }
            break;
        case 3: {
            [titleLabel setText:@"Page Google+"];
        }
            break;
        case 4: {
            NSDictionary* infoDict = [[NSBundle mainBundle] infoDictionary];
            NSString* version = [infoDict objectForKey:@"CFBundleShortVersionString"];
            [titleLabel setText:[NSString stringWithFormat:@"Allzic version %@",version]];
        }
            break;
        default:
            break;
    }
    [cell.contentView addSubview:titleLabel];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.accessoryType  = UITableViewCellAccessoryDisclosureIndicator;
    if (indexPath.row == 4) {
        cell.accessoryType  = UITableViewCellAccessoryNone;
    }
    cell.tag            = indexPath.row;
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    switch (indexPath.row) {
        case 0: {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.allzicradio.com"]];
        }
            break;
        case 1: {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://www.facebook.com/pages/Allzic-Radio/637360286300066?fref=ts"]];
        }
            break;
        case 2: {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://twitter.com/allzicradio"]];
        }
            break;
        case 3: {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://plus.google.com/+Allzicradio/posts"]];
        }
            break;
        default:
            break;
    }
}

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

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

@end
