//
//  NvTimeLabelView.m
//  SDKDemo
//
//  Created by shizhouhu on 2018/7/4.
 //
//

#import "NvTimeLabelView.h"
#import "NvButton.h"
#import "NvUtils.h"
#import "UIButton+NvButton.h"
#import "UILabel+NvLabel.h"
#import "UIColor+NvColor.h"
#import "Masonry.h"

@implementation NvTimeLabelView 

- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    
    NvButton *minusButton = [NvButton nv_buttonWithTitle:nil textColor:nil fontSize:-1 image:[NvUtils imageWithName:@"Nvminus"]];
    [self addSubview:minusButton];
    [minusButton addTarget:self action:@selector(onMinusButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    [minusButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(120*SCREANSCALE);
        make.top.equalTo(self).offset(4*SCREANSCALE);
        make.width.equalTo(@(12*SCREANSCALE));
        make.height.equalTo(@(12*SCREANSCALE));
    }];
    
    NvButton *addButton = [NvButton nv_buttonWithTitle:nil textColor:nil fontSize:-1 image:[NvUtils imageWithName:@"Nvadd"]];
    [self addSubview:addButton];
    [addButton addTarget:self action:@selector(onAddButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    [addButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(243*SCREANSCALE);
        make.top.equalTo(self).offset(4*SCREANSCALE);
        make.width.equalTo(@(12*SCREANSCALE));
        make.height.equalTo(@(12*SCREANSCALE));
    }];
    
    timeLabel = [UILabel nv_labelWithText:[NSString stringWithFormat:@"%@/%@", [NvUtils getFormattedTime:_currentPos], [NvUtils getFormattedTime:_duration]] fontSize:10*SCREANSCALE textColor:[UIColor nv_colorWithHexRGB:@"#FFFFFF"]];
    timeLabel.font = [NvUtils regularFontWithSize:10*SCREANSCALE];
    timeLabel.textAlignment = NSTextAlignmentCenter;
    [self addSubview:timeLabel];
    
    [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.centerY.equalTo(addButton);
        make.height.equalTo(@(14*SCREANSCALE));
    }];
    
    return self;
}

- (void)onMinusButtonClicked {
    if ([self.delegate respondsToSelector:@selector(onZoomOutClicked)]) {
        [self.delegate onZoomOutClicked];
    }
}

- (void)onAddButtonClicked {
    if ([self.delegate respondsToSelector:@selector(onZoomInClicked)]) {
        [self.delegate onZoomInClicked];
    }
}

- (void)updateLabel {
    timeLabel.text = [NSString stringWithFormat:@"%@/%@", [NvUtils getFormattedTime:_currentPos], [NvUtils getFormattedTime:_duration]];
}

@end
