//
//  ThingsAddCompleteViewController.m
//  
//
//  Created by Jason Lee on 11/13/15.
//
//

#import "ThingsAddCompleteViewController.h"
#import "ChangeDeviceNamePopupView.h"

@interface ThingsAddCompleteViewController ()<changeDeviceNameDelegate> {

}
@end


#pragma mark - Class Definition

@implementation ThingsAddCompleteViewController
//@synthesize deviceDetailModel;

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


- (void)initUI {
    
    _btnChange.enabled = NO;
    
    _lblTitle.text = [NSString stringWithFormat:@"%@ 추가 완료", _addDevice.prdName];
    _imgThings.image = [_addDevice imgaeForAddDel];
    _lblDesc.text = [_addDevice manufacturerName];
    
    if (_isDeleteMode) {
        _lblTitle.text = @"삭제 성공";
        _lblDesc.text = @"장치를 삭제했습니다";
    }
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [UIView animateWithDuration:kfAnimationDur animations:^{
        _maskView.alpha = 0.7;
    } completion:^(BOOL finished) {
        
        _constraintPopViewTop.constant = (IPHONE_HEIGHT - _popView.height) / 2;
        
        [UIView animateWithDuration:kfAnimationDur animations:^{
            [self.view layoutIfNeeded];
        }];
    }];
}

- (void)prepareViewDidLoad {
    
}


#pragma mark - UI Events

// 나중에 변경
- (IBAction)btnCompleteTouched:(id)sender {
    
    [[JDFacade facade] dismissModalStack:YES completion:^{
        [[JDFacade facade] gotoWishMenu:KNMenuIdThings];
    }];
}

// 이름 변경
- (IBAction)btnChangeTouched:(id)sender {

    ChangeDeviceNamePopupView *popup = [[ChangeDeviceNamePopupView alloc]initFromNib:_deviceDetailModel];
    popup.deviceDetailModel = _deviceDetailModel;
    popup.delegate = self;
    [popup show];
}

- (void)changeDeviceName:(NSString *)deviceName {
    
    [self btnCompleteTouched:nil];
}

-(void)receiveSocketData:(NSNotification *)notification
{
    _btnChange.enabled = YES;
    
//    deviceDetailModel = [[DeviceDetailModel alloc] initWithDictionary:notification.object error:nil];
}

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



@end
