//
//  RulesAddCompleteViewController.m
//  kneet2
//
//  Created by Jason Lee on 11/26/15.
//  Copyright © 2015 ntels. All rights reserved.
//

#import "RulesAddCompleteViewController.h"
#import "MainViewController.h"
#import "RuleModel.h"


@interface RulesAddCompleteViewController () {

}
@end


#pragma mark - Class Definition

@implementation RulesAddCompleteViewController


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


- (void)initUI {
    _lblRuleName.text = _refRule.ruleName;
    
    UIImage *timage = nil;
    if ([_refRule.triggerItemSubTypeCode isEqualToString:ksItemSubTypeCodeDevice]) {//디바이스일 경우,
        timage = [UIImage imageNamed:@"img_rule_trigger_icon_thingschange"];
        
    } else if ([_refRule.triggerItemSubTypeCode isEqualToString:ksItemSubTypeCodeTimer]) {//타이머일 경우,
        timage = [UIImage imageNamed:@"img_rule_trigger_icon_time"];
        
    } else if ([_refRule.triggerItemSubTypeCode isEqualToString:ksItemSubTypeCodeDaylight]) {//해뜰때/질때 경우,
        timage = [UIImage imageNamed:@"img_rule_trigger_icon_sunset"];
        
    } else if ([_refRule.triggerItemSubTypeCode isEqualToString:ksItemSubTypeCodeHeat]) {//더울때/추울때 경우,
        timage = [UIImage imageNamed:@"img_rule_trigger_icon_temperature"];
        
    }
    
    [_imgvIcon setImage:timage];
}

- (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 - Main Logic



#pragma mark - UI Events
- (IBAction)btnCompleteTouched:(id)sender {
    
    [[JDFacade facade] dismissModalStack:YES completion:^{
        [[JDFacade facade].mainViewController updateRulesListRecently];
    }];
}

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

@end