//
//  HomeHubConnectWifiViewController.m
//  OneCable
//
//  Created by nComz on 2017. 5. 11..
//  Copyright © 2017년 ntels. All rights reserved.
//

#import "HomeHubConnectWifiViewController.h"
#import "HomeHubWifiSearchViewController.h"

@interface HomeHubConnectWifiViewController () {
    
    BLEServiceHandler *bleService;
}

@end

@implementation HomeHubConnectWifiViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initUI];
    [self prepareViewDidLoad];
}


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

- (void)initUI {
    
    _lbTitle.text = @"선택하신 홈허브에\n등록된 Wi-Fi정보가 없습니다.";
    _lblSSID.hidden = YES;
    
    
    bleService = [BLEServiceHandler sharedManager];
    
    if ( [bleService isConnected] &&
        bleService.conDevice != nil &&
        !EQUALS([bleService getValueFromCharacteristic:kBLEChrRdSSID], @"-") ) {

        _lbTitle.text = @"선택하신 홈허브에\n현재 연결된 Wi-Fi입니다.";
        _lblSSID.text = [NSString stringWithFormat:@"SSID : %@", [bleService getValueFromCharacteristic:kBLEChrRdSSID]];
        _lblSSID.hidden = NO;
    }
    
    
}

- (void)prepareViewDidLoad {
    
    
}


#pragma mark - ble delegate
- (void)BLEWiFiSSIDUpdate:(NSString *)ssid {
    
    _lbTitle.text = @"선택하신 홈허브에\n현재 연결된 Wi-Fi입니다.";
    _lblSSID.text = [NSString stringWithFormat:@"SSID : %@", ssid];
    _lblSSID.hidden = NO;
    
}

- (void)BLEDisConnected:(BTLEDeivceModel *)info {
    
    [[JDFacade facade] toast:@"홈허브와 연결할 수 없습니다."];
    [self.navigationController popToRootViewControllerAnimated:YES];
    
}

#pragma mark - User Event
- (IBAction)btnNextTouched:(id)sender {
    
    HomeHubWifiSearchViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"HomeHubWifiSearchViewController" storyboardName:@"HomeHub"];
    vc.selectedModel = _selectedModel;
    
    [self.navigationController pushViewController:vc animated:YES];
    
}

- (IBAction)btnAgainSearchTouched:(id)sender {
    
    UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"HomeHubSearchViewController" storyboardName:@"HomeHub"];
    
    [self.navigationController pushViewController:vc animated:YES];
}

- (IBAction)btnCloseTouched:(id)sender {
    [self.navigationController popToRootViewControllerAnimated:YES];
}


@end
