//
//  CityRadiosViewController.m
//  Allzic
//
//  Created by Alia Bourouis on 28/05/14.
//  Copyright (c) 2014 Alia Bourouis. All rights reserved.
//

#import "CityRadiosViewController.h"
#import "AppDelegate.h"

@interface CityRadiosViewController ()

@end

@implementation CityRadiosViewController

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

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


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

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

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    int nbRowInSection = 0;
    if (dataArray != nil) {
        nbRowInSection = dataArray.count;
    }
    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 *radioTitleLabel = [[UILabel alloc]initWithFrame:CGRectMake(10.0f, 10.0f, tableView.frame.size.width - 40.0f, tableView.rowHeight - 20.0f)];
    [radioTitleLabel setText:[[dataArray objectAtIndex:indexPath.row]objectForKey:@"title"]];
    [radioTitleLabel setFont:[UIFont systemFontOfSize:16]];
    [radioTitleLabel setNumberOfLines:0];
    [radioTitleLabel setBackgroundColor:[UIColor clearColor]];
    [radioTitleLabel setTextColor:[UIColor blackColor]];
    [cell.contentView addSubview:radioTitleLabel];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.accessoryType  = UITableViewCellAccessoryDisclosureIndicator;
    cell.tag            = indexPath.row;
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    [appDelegate selectCountryWithData:[dataArray objectAtIndex:indexPath.row]];
    [appDelegate.categoriesRadiosVC setParentViewController:self];
    [appDelegate.categoriesRadiosVC setCurrentTabIndex:currentTabIndex];
}

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

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

@end
