//
//  ThingsDelValveCompleteViewController.m
//  OneCable
//
//  Created by nComz on 2017. 3. 23..
//  Copyright © 2017년 ntels. All rights reserved.
//

#import "ThingsGeneralDelCompleteViewController.h"
#import "CustomLabel.h"
#import "CustomButton.h"
#import "CustomImageView.h"

#import "ThingsGeneralDelStartViewController.h"
#import "MainViewController.h"
#import "ThingsViewController.h"
#import "ThingsDetailViewController.h"

@interface ThingsGeneralDelCompleteViewController ()

@end

@implementation ThingsGeneralDelCompleteViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self initUI];
    [self prepareViewDidLoad];
}

- (void)initUI {
    
}

- (void)prepareViewDidLoad {
    
    NSMutableString *title = [NSMutableString stringWithString:_delDevice.prdName];
    [title appendString:@" 삭제"];
    
    _imgThings.image = [_delDevice imgaeForAddDel];
    _lblManufacturer.text = [_delDevice manufacturerName];
    
    
    _imgThingsSuccess.hidden = !_isSuccess;
    _imgThingsFail.hidden = _isSuccess;
    
    _btnConfirm.hidden = !_isSuccess;
    _viewRetry.hidden = _isSuccess;
    
    if (_isSuccess) {
        [title appendString:@" 성공"];
    } else {
        [title appendString:@" 실패"];
    }
    
    _lblTitle.text = title;
}
/*
 
 - (void)finishDeviceDel:(BOOL)isSuccess {
 [self startLoading:NO];
 [self requestExcludeDevice:NO];
 ThingsGeneralDelCompleteViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"ThingsGeneralDelCompleteViewController" storyboardName:@"Things"];
 vc.delDevice = _delDevice;
 vc.isSuccess = isSuccess;
 //    vc.addableDevice = _addableDevice;
 
 vc.providesPresentationContextTransitionStyle = YES;
 vc.definesPresentationContext = YES;
 
 [vc setModalPresentationStyle:UIModalPresentationOverCurrentContext];
 
 UIViewController *pvc = self.presentingViewController;
 [self dismissViewControllerAnimated:NO completion:^{//TODO : UI Confirm with Mr.Mo
 [pvc presentViewController:vc animated:YES completion:nil];
 }];
 }
 
 */
- (IBAction)btnConfirmTouched:(id)sender {
    [self finishDelDevice];
}

- (IBAction)btnCancelTouched:(id)sender {
    [self finishDelDevice];
}

- (IBAction)btnRetryTouched:(id)sender {
    ThingsGeneralDelStartViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"ThingsGeneralDelStartViewController" storyboardName:@"Things"];
    
    vc.delDevice = _delDevice;
    
    [self showTransparencyModalView:vc];
}

-(void)finishDelDevice {
    
    
    [self dismissViewControllerAnimated:YES completion:^{
        
//        ThingsViewController *vc = [JDFacade facade].mainViewController.tvc;
//        if (vc && [vc isKindOfClass:[ThingsDetailViewController class]]) {
//            [vc finishDeviveDelete];
//        }  else {
//            ThingsDetailViewController *vc2 = (ThingsDetailViewController *)vc;
//            [vc2 finishDeviveDelete];
//        }
        
        ThingsDetailViewController *vc = (ThingsDetailViewController*)[JDFacade facade].currentViewController;

        if (vc && [vc isKindOfClass:[ThingsDetailViewController class]]) {
            
            [vc finishDeviveDelete];
            
        }  else {
            
            ThingsViewController *vc2 = [JDFacade facade].mainViewController.tvc;
            [vc2 finishDeviveDelete];
        }
    }];
}


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

@end
