//
//  SubViewController.m
//  AdViewSDKDemo
//
//  Created by unakayou on 11/1/19.
//  Copyright © 2019 AdView. All rights reserved.
//

#import "SubViewController.h"

@interface SubViewController ()

@end

@implementation SubViewController

- (UIScrollView *)backgroundScrollView {
    if (!_backgroundScrollView) {
        _backgroundScrollView = [[UIScrollView alloc] init];
        [self.view addSubview:_backgroundScrollView];
        self.backgroundScrollViewFrameSlider.hidden = NO;
    }
    return _backgroundScrollView;
}

//- (UISlider *)backgroundScrollViewFrameSlider {
//    if (!_backgroundScrollViewFrameSlider) {
//        _backgroundScrollViewFrameSlider = [[UISlider alloc] init];
//        _backgroundScrollViewFrameSlider.value = 1.0f;
//        _backgroundScrollViewFrameSlider.continuous = NO;
//        [_backgroundScrollViewFrameSlider addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];
//        [self.view addSubview:_backgroundScrollViewFrameSlider];
//        [self viewDidLayoutSubviews];
//    }
//    return _backgroundScrollViewFrameSlider;
//}

- (UILabel *)requestButton {
    if (!_requestButton) {
        _requestButton = [UILabel new];
        _requestButton.textAlignment = NSTextAlignmentCenter;
        _requestButton.textColor = [UIColor whiteColor];
        _requestButton.text = [NSString stringWithFormat:@"%@ %@", NSLocalizedString(@"REQ", nil),
                               [NSStringFromClass(self.class) stringByReplacingOccurrencesOfString:@"ViewController"
                                                                                        withString:@""]];
        _requestButton.backgroundColor = self.navigationController.navigationBar.barTintColor;
        _requestButton.userInteractionEnabled = YES;
        UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(requestButtonClick:)];
        [_requestButton addGestureRecognizer:tap];
        [self.view addSubview:_requestButton];
    }
    return _requestButton;
}

- (UILabel *)closebutton {
    if (!_closebutton) {
        _closebutton = [UILabel new];
        _closebutton.textAlignment = NSTextAlignmentCenter;
        _closebutton.textColor = [UIColor whiteColor];
        _closebutton.text = NSLocalizedString(@"CLOSE_BUTTON",nil);
        _closebutton.backgroundColor = self.navigationController.navigationBar.barTintColor;
        _closebutton.userInteractionEnabled = YES;
        UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeButtonClick:)];
        [_closebutton addGestureRecognizer:tap];
        [self.view addSubview:_closebutton];
    }
    return _closebutton;
}

- (void)sliderValueChanged:(id)slider {
    NSLog(@"%@",slider);
}

- (void)requestButtonClick:(UITapGestureRecognizer *)recognizer {
    NSLog(@"Error");
}

- (void)closeButtonClick:(UITapGestureRecognizer *)recognizer {
    NSLog(@"Error");
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = NSStringFromClass(self.class);
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor]};
}

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    
    CGFloat y = 0;
    self.requestButton.frame = CGRectMake((self.view.frame.size.width - 200) / 2,
                                          self.view.frame.size.height / 3 * 2,
                                          200,
                                          50);
    
    y = _requestButton.frame.origin.y - 100;
    
    _backgroundScrollViewFrameSlider.frame = CGRectMake(SPACE, y, self.view.frame.size.width - SPACE * 2, 50);
}

- (void)dealloc {
    NSLog(@"%s",__FUNCTION__);
}
@end
