//
//  RedPackageUNOpenView.m
//  Open
//
//  Created by 雷俊博 on 2020/3/19.
//  Copyright © 2020 黄江涛 . All rights reserved.
//

#import "RedPackageUNOpenView.h"

@interface RedPackageUNOpenView ()

@property (nonatomic, strong)UIImageView* backImg;

@property (nonatomic, strong)UILabel*lb_content;

@property (nonatomic, assign)RedPackageFrom fromType;

@end

@implementation RedPackageUNOpenView
- (instancetype)initWithFrame:(CGRect)frame type:(RedPackageFrom)fromType
{
    self = [super initWithFrame:frame];
    if (self) {
        self.fromType = fromType;
        [self setupUI];
    }
    return self;
}

- (void)setupUI
{
    
    UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapClick:)];
    
    
    
    self.backImg = [[UIImageView alloc]initWithFrame:self.bounds];
    self.backImg.userInteractionEnabled = YES;
    self.backImg.image = [UIImage imageNamed:@"package_unopen_bg"];
    
    [self.backImg addGestureRecognizer:tap];
    
    self.lb_content = [[UILabel alloc]init];
    _lb_content.textColor = [UIColor colorWithHex:0xf8f2bb];
    _lb_content.font = [UIFont systemFontOfSize:16];
    _lb_content.textAlignment = NSTextAlignmentCenter;
    _lb_content.numberOfLines = 0;
    [self addSubview:self.backImg];
    [self.backImg addSubview:_lb_content];
    [self.lb_content mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(171);
        make.centerX.equalTo(self);
        make.left.right.greaterThanOrEqualTo(self).offset(0);
    }];
    if (self.fromType == RedPackageFromRenZheng) {
        _lb_content.attributedText =  [self getAttributedWithString:@"恭喜您认证成功\n看看生活赠您一份随机红包" WithLineSpace:12 kern:0.5 font:[UIFont systemFontOfSize:16]];
    }else if (self.fromType == RedPackageFromWatchTV){
        _lb_content.attributedText =  [self getAttributedWithString:@"恭喜您观看成功\n看看生活赠您一份随机红包" WithLineSpace:12 kern:0.5 font:[UIFont systemFontOfSize:16]];
    }
  
    
    
    
}

#pragma mark - event repsonse
- (void)tapClick:(UITapGestureRecognizer *)tap
{
    if (self.btnClickBlock) {
        self.btnClickBlock(YES);
    }
}

- (NSAttributedString *)getAttributedWithString:(NSString *)string WithLineSpace:(CGFloat)lineSpace kern:(CGFloat)kern font:(UIFont *)font{
    NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];
    
    paragraphStyle.alignment = NSTextAlignmentCenter;
    
    //调整行间距
    paragraphStyle.lineSpacing = lineSpace;
    NSDictionary *attriDict = @{NSParagraphStyleAttributeName:paragraphStyle,NSKernAttributeName:@(kern),
        NSFontAttributeName:font};
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:string attributes:attriDict];
    return attributedString;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
