//
//  SignUpCompleteViewController.m
//  kneet
//
//  Created by Jason Lee on 4/27/15.
//  Copyright (c) 2015 ntels. All rights reserved.
//
#import "JDObject.h"

#import "CustomLabel.h"

#import "SignUpCompleteViewController.h"
#import "ThingsAddViewController.h"
#import "CustomButton.h"


@interface SignUpCompleteViewController () {
    ThingsAddViewController *_tvc;
}
@end


#pragma mark - Class Definition

@implementation SignUpCompleteViewController


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

    [self initUI];
    [self prepareViewDidLoad];
}


- (void)initUI {
    

    _scrollView.translatesAutoresizingMaskIntoConstraints = NO;
    
    //Localization
    _lblTitle.text = NSLocalizedString(@"장치 연결을 시작합니다", @"장치 연결을 시작합니다");
    [_btnRegisterLater setTitle:NSLocalizedString(@"나중에 등록하기", @"나중에 등록하기") forState:UIControlStateNormal];
}

- (void)prepareViewDidLoad {
    _lblHomeDesc.text = [NSString stringWithFormat:NSLocalizedString(@"%@이 만들어졌습니다\n장치를 연결해서 시작해보세요!", @"%@이 만들어졌습니다\n장치를 연결해서 시작해보세요!"), [JDFacade facade].tmpHomegrpName];
    
    _tvc = (ThingsAddViewController *)[CommonUtil instantiateViewControllerWithIdentifier:@"ThingsAddViewController" storyboardName:@"Things"];
    
    [self addChildViewController:_tvc];
    [_tvc didMoveToParentViewController:self];
    
    if ([self isViewLoaded]) {
        [_tvc beginAppearanceTransition:YES animated:NO];
        [_childContainerView addSubview:_tvc.view];
        _tvc.tableView.scrollEnabled = NO;
        [_tvc endAppearanceTransition];
        
        
        _constraintChildContainerViewHeight.constant = _constraintChildContainerViewHeight.constant * 5;//[_tvc.tableView numberOfRowsInSection:0];
        CGFloat contentHeight = 290 + _constraintChildContainerViewHeight.constant + 30 + 40 + 30;
        
        [_tvc.view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(_childContainerView);
            make.center.equalTo(_childContainerView);
        }];
        
        
        [self.view layoutIfNeeded];
        [_scrollView setContentSize:CGSizeMake(IPHONE_WIDTH, contentHeight)];
    }
}

#pragma mark - Main Logic



#pragma mark - UI Events

- (IBAction)bannerWallPadTouched:(id)sender
{
    UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"ThingsAddWallpadViewController" storyboardName:@"Things"];
    UINavigationController *nc = [[UINavigationController alloc] init];
    nc.viewControllers = @[vc];
    [[JDFacade facade] presentViewControllerByPush:nc pvc:self];
}

- (IBAction)bannerWallPadSubTouched:(id)sender
{
    //1. 등록된 월패드가 있는 지 체크
    
    UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"ThingsAddWallpadSubViewController" storyboardName:@"Things"];
    UINavigationController *nc = [[UINavigationController alloc] init];
    nc.viewControllers = @[vc];
    [[JDFacade facade] presentViewControllerByPush:nc pvc:self];
}


- (IBAction)bannerDawonTouched:(id)sender
{
    UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"ThingsAddPlugViewController" storyboardName:@"Things"];
    UINavigationController *nc = [[UINavigationController alloc] init];
    nc.viewControllers = @[vc];
    [[JDFacade facade] presentViewControllerByPush:nc pvc:self];
}

- (IBAction)bannerLiveCamTouched:(id)sender
{
    UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"ThingsAddCameraViewController" storyboardName:@"Things"];
    UINavigationController *nc = [[UINavigationController alloc] init];
    nc.viewControllers = @[vc];
    [[JDFacade facade] presentViewControllerByPush:nc pvc:self];
}

- (IBAction)bannerPhoneTouched:(id)sender {
//    if ([JDFacade facade].loginHomeGroup.deviceId && ![[JDFacade facade].loginHomeGroup.deviceId isEmptyString]) {
//        [[JDFacade facade] alert:NSLocalizedString(@"이미 등록하셨습니다", @"이미 등록하셨습니다")];
//        return;
//    }

    UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"ThingsAddGeofencingViewController" storyboardName:@"Things"];
    UINavigationController *nc = [[UINavigationController alloc] init];
    nc.viewControllers = @[vc];
    [[JDFacade facade] presentViewControllerByPush:nc pvc:self];
}

- (IBAction)btnRegisterLaterTouched:(id)sender {

    UIViewController *rvc = [JDFacade facade].appDelegate.window.rootViewController;
    if (rvc.presentedViewController || (rvc.presentingViewController && (rvc.modalPresentationStyle == UIModalPresentationFullScreen))){
        [rvc dismissViewControllerAnimated:NO completion:nil];
    }

    UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"DashboardViewController" storyboardName:@"Main"];
    UINavigationController *nc = [[UINavigationController alloc] init];
    nc.viewControllers = @[vc];

    [JDFacade facade].appDelegate.window.rootViewController = nc;
}


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



@end
