//
//  AccidentsListVC.m
//  Gilliatte
//
//  Created by Lead on 17/09/16.
//  Copyright © 2016 Lead infosoft. All rights reserved.
//

#import "AccidentsListVC.h"
#import "AccidentsVC.h"
#import "AccidentsListCell.h"
#import "ApiUtillity.h"
#import "AFNetworking.h"
#import "ActionSheetPicker.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import "UIImageView+UIActivityIndicatorForSDWebImage.h"
#import "KIImagePager.h"





@interface AccidentsListVC ()<AccidentDelegate>{
    NSInteger SelectedProject;
    NSInteger SelectedJob;
    NSInteger SelectedSub;
    NSInteger SelectedEmployee;
    
    NSMutableArray *ProjectArray;
    NSMutableArray *EmployeeArray;
    NSMutableArray *SubArray;
    NSMutableArray *UserDataArray;
    NSMutableArray *JobArray;
    
    NSMutableArray *getAccidentData;
    NSMutableArray *EditedArray;
    
    BOOL TableReload;
    NSMutableArray *PopUpNameArray;
    NSMutableArray *PopsplitNameArray,*PopsplitPhoneArray,*PopsplitDescArray;
    
    NSString *DeleteRecordID;
    NSUInteger deleteIndex;
    NSIndexPath *deleteTableIndex;
    
    IBOutlet KIImagePager *_imagePager;
    NSMutableArray *ImagesDisplayDataArray;
    

    
}
//details
@end

@implementation AccidentsListVC

- (void)viewDidLoad {
    [super viewDidLoad];
    //    SelectedProject = 0;
    //    SelectedJob = 0;
    //    SelectedSub = 0;
    //    SelectedEmployee = 0;
    
    TableReload = 0;
    PopUpNameArray = [[NSMutableArray alloc]init];
    PopsplitNameArray = [[NSMutableArray alloc]init];
    PopsplitPhoneArray = [[NSMutableArray alloc]init];
    PopsplitDescArray = [[NSMutableArray alloc]init];
    
    JobArray = [[NSMutableArray alloc]init];
    UserDataArray = [[NSMutableArray alloc]init];
    ProjectArray = [[NSMutableArray alloc]init];
    EmployeeArray = [[NSMutableArray alloc]init];
    SubArray = [[NSMutableArray alloc]init];
    ImagesDisplayDataArray=[[NSMutableArray alloc]init];
    
    
    getAccidentData = [[NSMutableArray alloc]init];
    EditedArray = [[NSMutableArray alloc]init];
}


-(void)viewWillAppear:(BOOL)animated{
    TableReload = 0;
    
    SelectedProject = [ApiUtillity getProjectNumber];
    SelectedJob = [ApiUtillity getJobNumber];
    
    _view_PopUp.hidden = true;
    _View_ImgViewPopUp.hidden=true;
    
//    [self getAccidentData];
    [self getUserDefaultData];
    [self getAccidentData];

    
}

-(void)viewDidAppear:(BOOL)animated
{
    _imagePager.pageControl.currentPageIndicatorTintColor = [UIColor lightGrayColor];
    _imagePager.pageControl.pageIndicatorTintColor = [UIColor blackColor];
    _imagePager.slideshowTimeInterval = 5.5f;
    _imagePager.slideshowShouldCallScrollToDelegate = YES;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


#pragma mark- ButtonAction
- (IBAction)btn_bar_Back:(id)sender {
    [self.navigationController popViewControllerAnimated:true];
}

-(IBAction)Btn_OpenImagview:(id)sender
{
    UIButton *btn=(UIButton *)sender;
    _View_ImgViewPopUp.hidden=false;
    _view_PopUp.hidden=true;
    _View_DispalyList.hidden=true;
    
    
    
//    [cell.imageview_AddCompany setImageWithURL:[NSURL URLWithString:[[ImagesDataArray objectAtIndex:indexPath.row] valueForKey:@"image"]] usingActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
//
    

    
//    NSString *img = [[getAccidentData valueForKey:@"photo"]objectAtIndex:btn.tag-1000];
////    [_Imgview_NewPopUp sd_setImageWithURL:[NSURL URLWithString:img] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
////    }];
//    
//       [_Imgview_NewPopUp setImageWithURL:[NSURL URLWithString:img] usingActivityIndicatorStyle:(UIActivityIndicatorViewStyleGray)];
    
    ImagesDisplayDataArray= [[getAccidentData valueForKey:@"photos"]objectAtIndex:btn.tag-1000];
                             
    
    
    if (ImagesDisplayDataArray.count)
    {
        [_imagePager reloadData];
        
    }
    else
    {
        
    }
    
    NSLog(@"BUtton Check");
    
    
    
    
}

- (IBAction)btn_Handler_Project:(id)sender {
    NSLog(@"%@",ProjectArray);
    NSMutableArray *ProjectSubArray = [[NSMutableArray alloc]init];
    NSArray *Project = [[NSArray alloc]init];
    int i;
    for (i=0; i<ProjectArray.count; i++) {
        [ProjectSubArray addObject:[[ProjectArray objectAtIndex:i]valueForKey:@"project_name"]];
    }
    Project = ProjectSubArray;
    [ActionSheetStringPicker showPickerWithTitle:@"Select Project"
                                            rows:Project
                                initialSelection:SelectedProject
                                       doneBlock:^(ActionSheetStringPicker *picker, NSInteger selectedIndex, id selectedValue) {
                                           NSLog(@"Picker: %@, Index: %ld, value: %@",
                                                 picker, (long)selectedIndex, selectedValue);
                                           SelectedProject = selectedIndex;
                                           SelectedJob = 0;
                                           
                                           [_btn_Project setTitle:[NSString stringWithFormat:@"%@", selectedValue] forState:UIControlStateNormal];
                                           //Set JOb Title
//                                           JobArray = [[ProjectArray objectAtIndex:selectedIndex]valueForKey:@"jobs"];
//                                           [_btn_Job setTitle:[[JobArray objectAtIndex:0] valueForKey:@"job_title"] forState:UIControlStateNormal];
                                           
                                           //Set UserDefault Project_ID
                                           NSString *ProjectId = [[ProjectArray objectAtIndex:selectedIndex]valueForKey:@"project_id"];
                                           [[NSUserDefaults standardUserDefaults] setObject:ProjectId forKey:@"PROJECT_ID"];
                                           //Set UserDefault JOb_Id
//                                           NSString *JobId = [[JobArray objectAtIndex:0]valueForKey:@"job_id"];
//                                           [[NSUserDefaults standardUserDefaults] setObject:JobId forKey:@"JOB_ID"];
                                           
                                           [self getAccidentData];
                                       }
                                     cancelBlock:^(ActionSheetStringPicker *picker) {
                                         NSLog(@"Block Picker Canceled");}
                                          origin:sender];
}


- (IBAction)btn_Handler_Job:(id)sender {
    NSArray *Job = [[NSArray alloc]init];
    NSMutableArray *JobSubArray = [[NSMutableArray alloc]init];
    //    JobArray = [[ProjectArray objectAtIndex:SelectedProjectB]valueForKey:@"jobs"];
    int i;
    for (i=0; i<JobArray.count; i++) {
        [JobSubArray addObject:[[JobArray objectAtIndex:i] valueForKey:@"job_title"]];
    }
    Job = JobSubArray;
    [ActionSheetStringPicker showPickerWithTitle:@"Select Job"
                                            rows:Job
                                initialSelection:SelectedJob
                                       doneBlock:^(ActionSheetStringPicker *picker, NSInteger selectedIndex, id selectedValue) {
                                           NSLog(@"Picker: %@, Index: %ld, value: %@",
                                                 picker, (long)selectedIndex, selectedValue);
                                           SelectedJob = selectedIndex;
                                           [_btn_Job setTitle:[NSString stringWithFormat:@"%@", selectedValue] forState:UIControlStateNormal];
                                           
                                           //Set UserDefault JOb_Id
//                                           NSString *JobId = [[JobArray objectAtIndex:selectedIndex]valueForKey:@"job_id"];
//                                           [[NSUserDefaults standardUserDefaults] setObject:JobId forKey:@"JOB_ID"];
                                           
                                           [self getAccidentData];
                                       }
                                     cancelBlock:^(ActionSheetStringPicker *picker) {
                                         NSLog(@"Block Picker Canceled");
                                     }
                                          origin:sender];
}


- (IBAction)btn_Handler_Add:(id)sender {
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        AccidentsVC *VC = (AccidentsVC *)[storyboard instantiateViewControllerWithIdentifier:@"AccidentsVC"];
        VC.delegate = self;
        [self.navigationController pushViewController:VC animated:true];
    }
    else{
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStory_iPad" bundle:nil];
        AccidentsVC *VC = (AccidentsVC *)[storyboard instantiateViewControllerWithIdentifier:@"AccidentsVC"];
        VC.delegate = self;
        [self.navigationController pushViewController:VC animated:true];
    }
}


- (IBAction)btn_Handler_Save:(id)sender {
    
}


- (IBAction)btn_Handler_Edit:(id)sender {
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        AccidentsVC *VC = (AccidentsVC *)[storyboard instantiateViewControllerWithIdentifier:@"AccidentsVC"];
        VC.delegate = self;
        VC.isEdited = [[NSString alloc]init];
        VC.isEdited = @"YES";
        VC.EditedArray = [[NSMutableArray alloc]init];
        VC.EditedsplitNameArray = [[NSMutableArray alloc]init];
        VC.EditedsplitPhoneArray = [[NSMutableArray alloc]init];
        VC.EditedArray = EditedArray;
        VC.EditedsplitNameArray = PopsplitNameArray;
        VC.EditedsplitPhoneArray = PopsplitPhoneArray;
        VC.EditedsplitDescArray = PopsplitDescArray;
        [self.navigationController pushViewController:VC animated:true];
    }
    else{
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStory_iPad" bundle:nil];
        AccidentsVC *VC = (AccidentsVC *)[storyboard instantiateViewControllerWithIdentifier:@"AccidentsVC"];
        VC.delegate = self;
        VC.isEdited = [[NSString alloc]init];
        VC.isEdited = @"YES";
        VC.EditedArray = [[NSMutableArray alloc]init];
        VC.EditedsplitNameArray = [[NSMutableArray alloc]init];
        VC.EditedsplitPhoneArray = [[NSMutableArray alloc]init];
        VC.EditedArray = EditedArray;
        VC.EditedsplitNameArray = PopsplitNameArray;
        VC.EditedsplitPhoneArray = PopsplitPhoneArray;
        VC.EditedsplitDescArray = PopsplitDescArray;
        [self.navigationController pushViewController:VC animated:true];
    }
}


- (IBAction)btn_Handler_Cancel:(id)sender {
    TableReload = 0;
    _view_PopUp.hidden = true;
}

#pragma mark - KIImagePager DataSource
- (NSArray *) arrayWithImages:(KIImagePager*)pager
{
    return ImagesDisplayDataArray;
    
    
}

- (UIViewContentMode) contentModeForImage:(NSUInteger)image inPager:(KIImagePager *)pager
{
    return UIViewContentModeScaleAspectFit;
}

- (NSString *) captionForImageAtIndex:(NSUInteger)index inPager:(KIImagePager *)pager
{
    return 0;
    
}

#pragma mark - KIImagePager Delegate
- (void) imagePager:(KIImagePager *)imagePager didScrollToIndex:(NSUInteger)index
{
    NSLog(@"%s %lu", __PRETTY_FUNCTION__, (unsigned long)index);
}

- (void) imagePager:(KIImagePager *)imagePager didSelectImageAtIndex:(NSUInteger)index
{
    NSLog(@"%s %lu", __PRETTY_FUNCTION__, (unsigned long)index);
}


#pragma mark- All Methode
-(void)getRecordArray:(NSMutableArray *)recordArray{
    [getAccidentData removeAllObjects];
    [PopUpNameArray removeAllObjects];
    
    NSMutableArray *dataArray = [[NSMutableArray alloc]init];
    dataArray = recordArray;
    for (NSMutableDictionary *Dic in dataArray) {
        [getAccidentData addObject:Dic];
        [PopUpNameArray addObject:[Dic valueForKey:@"witness"]];
    }
    TableReload = 0;
    [_tableview_Desc reloadData];
    
//    getAccidentData = recordArray;
//    PopUpNameArray = [getAccidentData valueForKey:@"witness"];
//    [_tableview_Desc reloadData];
}


- (void) getUserDefaultData{
    ProjectArray = [[NSUserDefaults standardUserDefaults] objectForKey:@"ProjectArray"];
    SubArray = [[NSUserDefaults standardUserDefaults] objectForKey:@"SubArray"];
    EmployeeArray = [[NSUserDefaults standardUserDefaults] objectForKey:@"EmployeeArray"];
    
    
    //SET PROJECT AND JOB DATA...
    NSString *TempProjectID,*TempJobID;
    
    if ((TempProjectID = [[NSUserDefaults standardUserDefaults]objectForKey:@"PROJECT_ID"])) {
        int TempproID = [TempProjectID intValue];
        int TempjobID = [TempJobID intValue];
        NSLog(@"TempjobId:-- %d",TempjobID);
        
        //FOR Project & Job...
        int i;
        for (i=0; i<ProjectArray.count; i++) {
            NSString *proID,*jobID;
            NSLog(@"Job Id:-- %@",jobID);
            
            proID = [[ProjectArray objectAtIndex:i] valueForKey:@"project_id"];
            if ([proID intValue] == TempproID) {
                //SET UI DATA
                [_btn_Project setTitle:[[ProjectArray objectAtIndex:i]valueForKey:@"project_name"] forState:UIControlStateNormal];
//                JobArray = [[ProjectArray objectAtIndex:i]valueForKey:@"jobs"];
//                int x;
//                for (x=0; x<JobArray.count; x++) {
//                    jobID = [[JobArray objectAtIndex:x] valueForKey:@"job_id"];
//                    if ([jobID intValue] == TempjobID) {
//                        [_btn_Job setTitle:[[JobArray objectAtIndex:x] valueForKey:@"job_title"] forState:UIControlStateNormal];
//                    }
//                }
            }
        }
    }
    
}


-(void) getAccidentData{
    
    NSString *ProID,*JobID,*Date,*UID,*Type;
    NSData *GetUserData;
    if ((GetUserData = [[NSUserDefaults standardUserDefaults] objectForKey:@"USER_PROFILE"])) {
        NSMutableArray *savedArray = [NSKeyedUnarchiver unarchiveObjectWithData:GetUserData];
        NSMutableArray *UserArray = [[NSMutableArray alloc]init];
        UserArray = savedArray;
        
        NSLog(@"%@",UserArray);
        UID = [NSString stringWithFormat:@"%@",[UserArray valueForKey:@"uid"]];
    }
    if (!(Date = [[NSUserDefaults standardUserDefaults] objectForKey:@"SELECTED_DATE"]))
    {
        return;
    }
    else{
        NSArray *DateSeperate = [Date componentsSeparatedByString:@"/"];
        NSString *Day,*Month,*Year,*OriginalDate;
        OriginalDate = [[NSString alloc]init];
        Day = [DateSeperate objectAtIndex:0];
        Month = [DateSeperate objectAtIndex:1];
        Year = [DateSeperate objectAtIndex:2];
        
        OriginalDate = [OriginalDate stringByAppendingString:Year];
        OriginalDate = [OriginalDate stringByAppendingString:@"-"];
        OriginalDate = [OriginalDate stringByAppendingString:Month];
        OriginalDate = [OriginalDate stringByAppendingString:@"-"];
        OriginalDate = [OriginalDate stringByAppendingString:Day];
        
        Date = OriginalDate;
    }
    if (!(ProID = [[NSUserDefaults standardUserDefaults] objectForKey:@"PROJECT_ID"]))
    {
        return;
    }
    if ((!(JobID = [[NSUserDefaults standardUserDefaults] objectForKey:@"JOB_ID"]))) {
        JobID = @"-1";
    }
    
    Type = @"accident";
    [ApiUtillity setSVProgressHUDView:self.view];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    [manager.requestSerializer setTimeoutInterval:150.0];

    
    NSDictionary *params = @{@"date":Date,@"uid":UID,@"project_id":ProID,@"job_id":JobID};
    
    [manager POST:@"http://p4bdesigns.com/Gilliatteweb/app/api3/accident_get.php" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
        if (responseObject != nil) {
            NSString *Suceess;
            if ((Suceess = [responseObject valueForKey:@"success"])) {
                if ([Suceess  isEqual: @"ok"]) {
                    [getAccidentData removeAllObjects];
                    [PopUpNameArray removeAllObjects];
                    
                    NSMutableArray *dataArray;
                    dataArray = [responseObject valueForKey:@"records"];
                    for (NSMutableDictionary *Dic in dataArray) {
                        [getAccidentData addObject:Dic];
                        [PopUpNameArray addObject:[Dic valueForKey:@"witness"]];
                    }
                    
//                    NSMutableArray *Witness;
//                    Witness = [getAccidentData valueForKey:@"witness"][0];
//                    for (NSMutableDictionary *Dic in Witness) {
//                        [PopUpNameArray addObject:Dic];
//                    }
                    
                    [_tableview_Desc reloadData];
                }
            }
        }
        [ApiUtillity dissmissSVProgressHUDView:self.view];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"Error: %@", error);
        NSInteger statusCode = error.code;
        NSLog(@"%d",(int)statusCode);
        
        if(statusCode == -1001) {
            // request timed out
            NSLog(@"request timed out");
            [ApiUtillity setSVProgressHUDInfoView:self.view];
        }
        else if (statusCode == -1005){
            [ApiUtillity setSVProgressHUDInfoView:self.view];
        }
        else if (statusCode == -1009 || statusCode == -1004) {
            // no internet connectivity
            NSLog(@"No Internet Connection");
            UIAlertView *alert = [[UIAlertView alloc]init];
            alert = [[UIAlertView alloc]initWithTitle:@"Error" message:@"No Internet Connection" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
            [alert show];
        }
        
            [ApiUtillity dissmissSVProgressHUDView:self.view];
        
    }];
    
}


-(void) DeleteAccidentData{
    [ApiUtillity setSVProgressHUDView:self.view];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    NSDictionary *params = @{@"id":DeleteRecordID};
    
    [manager POST:@"http://p4bdesigns.com/Gilliatteweb/app/api3/accident_delete.php" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
        if (responseObject != nil) {
            NSString *Suceess;
            if ((Suceess = [responseObject valueForKey:@"success"])) {
                if ([Suceess  isEqual: @"Deleted"]) {
//                    [self getAccidentData];
                    
                    [getAccidentData removeObjectAtIndex:deleteIndex];
                    [_tableview_Desc deleteRowsAtIndexPaths:@[deleteTableIndex] withRowAnimation:UITableViewRowAnimationFade];
                    [_tableview_Desc reloadData];
                }
            }
        }
        [ApiUtillity dissmissSVProgressHUDView:self.view];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"Error: %@", error);
        NSInteger statusCode = error.code;
        NSLog(@"%d",(int)statusCode);
        
        if(statusCode == -1001) {
            // request timed out
            NSLog(@"request timed out");
            [ApiUtillity setSVProgressHUDInfoView:self.view];
        }
        else if (statusCode == -1005){
            [ApiUtillity setSVProgressHUDInfoView:self.view];
        }
        else if (statusCode == -1009 || statusCode == -1004) {
            // no internet connectivity
            NSLog(@"No Internet Connection");
            UIAlertView *alert = [[UIAlertView alloc]init];
            alert = [[UIAlertView alloc]initWithTitle:@"Error" message:@"No Internet Connection" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
            [alert show];
        }
        
            [ApiUtillity dissmissSVProgressHUDView:self.view];
        
    }];
}


-(void) showPopUp:(NSUInteger)number{
    _view_PopUp.hidden = false;
    
    TableReload = 1;
    [_tableview_PopUp reloadData];
    
    _lbl_DateTime_PopUp.text = [[getAccidentData valueForKey:@"incident_datetime"]objectAtIndex:number];
    _lbl_Company_PopUp.text = [[getAccidentData valueForKey:@"company"]objectAtIndex:number];
    _lbl_Name_PopUp.text = [[getAccidentData valueForKey:@"name"]objectAtIndex:number];
    _lbl_Phone_PopUp.text = [[getAccidentData valueForKey:@"phone"]objectAtIndex:number];
    _lbl_IncidenceType_PopUp.text = [[getAccidentData valueForKey:@"incident_type"]objectAtIndex:number];
    _lbl_Status_PopUp.text = [[getAccidentData valueForKey:@"status"]objectAtIndex:number];
    _lbl_Desc_PopUp.text = [[getAccidentData valueForKey:@"description"]objectAtIndex:number];
}


#pragma mark- Tableview Methode
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSLog(@"%@",tableView);
    if (TableReload == 1 && PopUpNameArray.count == 0) {
        UILabel *noDataLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.tableview_Desc.bounds.size.width, self.tableview_Desc.bounds.size.height)];
        noDataLabel.text             = @"No Data Found.";
        noDataLabel.textColor        = [UIColor blackColor];
        noDataLabel.textAlignment    = NSTextAlignmentCenter;
        self.tableview_Desc.backgroundView = noDataLabel;
        self.tableview_Desc.separatorStyle = UITableViewCellSeparatorStyleNone;
        return 0;
    }
    if (TableReload == 0) {
        self.tableview_Desc.backgroundView = nil;
        
        return getAccidentData.count;
    }
    else{
        self.tableview_Desc.backgroundView = nil;
        
        NSLog(@"%lu",(unsigned long)PopUpNameArray.count);
        return PopsplitNameArray.count;
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (TableReload == 0) {
        static NSString *Indentifier = @"AccidentsListCell";
        AccidentsListCell *cell = [_tableview_Desc dequeueReusableCellWithIdentifier:Indentifier];
        if (cell == nil) {
            cell = [[AccidentsListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Indentifier];
        }
        
        cell.lbl_Date.text = [[getAccidentData valueForKey:@"incident_datetime"]objectAtIndex:indexPath.row];
        cell.lbl_CompanyName.text = [[getAccidentData valueForKey:@"company"]objectAtIndex:indexPath.row];
        cell.lbl_name.text = [[getAccidentData valueForKey:@"name"]objectAtIndex:indexPath.row];
        cell.lbl_MobileNo.text = [[getAccidentData valueForKey:@"phone"]objectAtIndex:indexPath.row];
        cell.lbl_Desc.text = [[getAccidentData valueForKey:@"description"]objectAtIndex:indexPath.row];
        
        cell.Btn_HandlerImgViewOpen.tag=indexPath.row+1000;

        [cell.Btn_HandlerImgViewOpen addTarget:self action:@selector(Btn_OpenImagview:) forControlEvents:UIControlEventTouchUpInside];
        
//        NSString *img = [[getAccidentData valueForKey:@"photo"]objectAtIndex:indexPath.row];
//        [cell.ImgView_AccidentImgview sd_setImageWithURL:[NSURL URLWithString:img] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
//        }];

        
         [cell.ImgView_AccidentImgview setImageWithURL:[NSURL URLWithString:[[getAccidentData objectAtIndex:indexPath.row] valueForKey:@"photo"]] usingActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
        
        
     //   [cell.ImgView_AccidentImgview setImageWithURL:url usingActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
        

        
        return cell;
    }
    else{
        static NSString *Indentifier = @"cellPopUp";
        UITableViewCell *cell = [_tableview_PopUp dequeueReusableCellWithIdentifier:Indentifier];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Indentifier];
        }
        
        UILabel *Name = [cell viewWithTag:1];
        Name.text = [PopsplitNameArray objectAtIndex:indexPath.row];
        
        UILabel *Number = [cell viewWithTag:2];
        Number.text = [PopsplitPhoneArray objectAtIndex:indexPath.row];
        
        return cell;
    }
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView.tag == 1) {
        return;
    }
    
    [PopsplitNameArray removeAllObjects];
    [PopsplitPhoneArray removeAllObjects];
    [PopsplitDescArray removeAllObjects];
    
    int i;
    NSMutableArray *DicName,*DicPhone,*DicDesc;
    DicName = [PopUpNameArray objectAtIndex:indexPath.row];
    DicPhone = [PopUpNameArray objectAtIndex:indexPath.row];
    DicDesc = [PopUpNameArray objectAtIndex:indexPath.row];
    for (i = 0; i < DicName.count; i++) {
        NSArray *NAME,*PHONE,*DESC;
        NAME = [[DicName valueForKey:@"name"]objectAtIndex:i];
        PHONE = [[DicPhone valueForKey:@"phone"]objectAtIndex:i];
        DESC = [[DicDesc valueForKey:@"details"]objectAtIndex:i];
        
        [PopsplitNameArray addObject:NAME];
        [PopsplitPhoneArray addObject:PHONE];
        [PopsplitDescArray addObject:DESC];
    }
    
    [self showPopUp:indexPath.row];
    EditedArray = [getAccidentData objectAtIndex:indexPath.row];
}


-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView.tag == 1) {
        return;
    }
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        deleteIndex = indexPath.row;
        deleteTableIndex = indexPath;
        
        DeleteRecordID = [[getAccidentData valueForKey:@"id"] objectAtIndex:indexPath.row];
        [self DeleteAccidentData];
    }
}

- (IBAction)btn_imgviewCancel:(id)sender {

    _View_ImgViewPopUp.hidden=true;
    _view_PopUp.hidden=true;
    _View_DispalyList.hidden=false;

}
@end