//
//  CheckSelectorViewController.m
//  AntsContract
//
//  Created by Ray on 12/22/16.
//  Copyright © 2016 United Software Applications, Inc. All rights reserved.
//

#import "CheckSelectorViewController.h"

@interface CheckSelectorViewController ()

@end

@implementation CheckSelectorViewController

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

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)OnOKClick:(id)sender {
    [self dismissViewControllerAnimated:false completion:^{
        if(self.blk_OK)
            self.blk_OK(self.checkedData);
    }];
}
- (IBAction)OnCancelClick:(id)sender {
    
    [self dismissViewControllerAnimated:false completion:nil];
}

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

#pragma mark - Table view data source
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
{

    return 44;
    
    
}



- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    
    return @"";//[NSString stringWithFormat:@"Signature%ld",(long)section];
    
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    

    NSString *CellIdentifier = @"CheckItemCell";
    UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    
    NSArray *item_arr = self.rowData[indexPath.row];
    
    cell.textLabel.text = item_arr[0];

    return cell;
}
- (UITableViewCellAccessoryType)tableView:(UITableView*)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath*)indexPath
{
    if([self.checkedData containsObject:[NSNumber numberWithLong:indexPath.row]])
    {
        return UITableViewCellAccessoryCheckmark;
    }
    else
    {
        return UITableViewCellAccessoryNone;
    }
}
#pragma mark tableview delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
        UITableViewCell* cell = [tableView cellForRowAtIndexPath:indexPath];
    if(self.single_select)
    {
        [self.checkedData removeAllObjects];
        if(cell.accessoryType==UITableViewCellAccessoryNone)
            [self.checkedData addObject:[NSNumber numberWithLong:indexPath.row] ];
        
    }
    else
    {
        if([self.checkedData containsObject:[NSNumber numberWithLong:indexPath.row]])
        {
            [self.checkedData removeObject:[NSNumber numberWithLong:indexPath.row]];
            
        }
        else
        {
            [self.checkedData addObject:[NSNumber numberWithLong:indexPath.row] ];
        }
        
    }
    

   // cell.accessoryType=UITableViewCellAccessoryCheckmark;
    
    [tableView reloadData];
    
    

//    if(self.blk_Select)
//    {
//        
//        //        SignatureTableViewCell * cell= [tableView cellForRowAtIndexPath:indexPath];
//        
//        NSDictionary * item_json = self.signatureData[[NSString stringWithFormat:@"item_%ld",(long)indexPath.section]];
//        
//        //        UIImage* img = [UIImage imageWithContentsOfFile:item_json[@"file"]];
//        
//        
//        self.blk_Select(item_json[@"file"]);
//        
//    }
//    
//    [self dismissViewControllerAnimated:false completion:nil];
    
 
    
    
}



@end
