//
//  imageVersionRenewTipView.m
//  隐私保护
//
//  Created by xd h on 2023/12/21.
//

#import "imageVersionRenewTipView.h"
@interface imageVersionRenewTipView ()
@property (nonatomic,strong) UIView* whiteBgView;
@end

@implementation imageVersionRenewTipView

- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    self.backgroundColor = [UIColor hwColor:@"000000" alpha:0.6];
    [self drawAnyView];
    
    return self;
}

- (void)drawAnyView{
    _whiteBgView = [UIView new];
    _whiteBgView.layer.cornerRadius = 8;
    _whiteBgView.backgroundColor = [UIColor whiteColor];
    [self addSubview:_whiteBgView];
    
    [_whiteBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(332);
        make.width.mas_equalTo(300.f);
        make.centerY.mas_equalTo(-50.f);
        make.centerX.mas_equalTo(0.f);
    }];
    
    UIImageView *topImage = [[UIImageView alloc] init];
    topImage.image = [UIImage imageNamed:@"imageVersionTipBg"];
    [_whiteBgView addSubview:topImage];
    
    [topImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(160);
        make.width.mas_equalTo(300.f);
        make.left.mas_equalTo(0.f);
        make.top.mas_equalTo(-40.f);
    }];
    
    NSString *curTitleStr = NSLocalizedString(@"image_version_pop_title",nil);
    UILabel *titleLab = [[UILabel alloc] init];
    titleLab.text = curTitleStr;
    titleLab.numberOfLines = 0;
    titleLab.textColor = [UIColor whiteColor];
    titleLab.font = [UIFont boldSystemFontOfSize:22.0];
    [topImage addSubview:titleLab];
    
    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(60);
        make.right.mas_equalTo(0.f);
        make.left.mas_equalTo(25.f);
        make.top.mas_equalTo(55.f);
    }];
    
    NSString *curTip1Str = NSLocalizedString(@"image_version_pop_tip1",nil);
    UILabel *tip1Lab = [[UILabel alloc] init];
    tip1Lab.text = curTip1Str;
    tip1Lab.numberOfLines = 0;
    tip1Lab.textAlignment = NSTextAlignmentCenter;
    tip1Lab.textColor = [UIColor hwColor:@"#151515" alpha:1.0];
    tip1Lab.font = [UIFont systemFontOfSize:16.0];
    [_whiteBgView addSubview:tip1Lab];
    
    CGFloat curHeight = [curTip1Str boundingRectWithSize:CGSizeMake(280, 1000) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16.0]} context:nil].size.height;
    
    curHeight += 15;
    
    [tip1Lab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(curHeight);
        make.right.mas_equalTo(-10.f);
        make.left.mas_equalTo(10.f);
        make.top.mas_equalTo(topImage.mas_bottom).offset(20.f);
    }];
    
    NSString *curTip2Str = NSLocalizedString(@"image_version_pop_tip2",nil);
    
    CGFloat curHeight2 = [curTip2Str boundingRectWithSize:CGSizeMake(280, 1000) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16.0]} context:nil].size.height;
    
    curHeight2 += 5;
    
    UILabel *tip2Lab = [[UILabel alloc] init];
    tip2Lab.text = curTip2Str;
    tip2Lab.numberOfLines = 0;
    tip2Lab.textAlignment = NSTextAlignmentCenter;
    tip2Lab.textColor = [UIColor hwColor:@"#151515" alpha:0.5];
    tip2Lab.font = [UIFont systemFontOfSize:14.0];
    [_whiteBgView addSubview:tip2Lab];
    //tip2Lab.backgroundColor = [UIColor greenColor];
    
    [tip2Lab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(curHeight2);
        make.right.mas_equalTo(-10.f);
        make.left.mas_equalTo(10.f);
        make.top.mas_equalTo(tip1Lab.mas_bottom).offset(10.f);
    }];
    
    [_whiteBgView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(240 + curHeight + curHeight2);
        make.width.mas_equalTo(300.f);
        make.centerY.mas_equalTo(-50.f);
        make.centerX.mas_equalTo(0.f);
    }];
    
    UIButton *konwBut = [[UIButton alloc] init];
    [konwBut setTitle:NSLocalizedString(@"guide_set_pwd_guide_know",nil) forState:UIControlStateNormal];
    konwBut.layer.cornerRadius = 8;
    konwBut.layer.masksToBounds = YES;
    [konwBut addTarget:self action:@selector(colseFun) forControlEvents:UIControlEventTouchUpInside];
    [_whiteBgView addSubview:konwBut];
    
    CAGradientLayer *gradientLayer = [CAGradientLayer layer];
    gradientLayer.frame = CGRectMake(0, 0, 160, 48);
    gradientLayer.colors = @[(__bridge NSString *)[UIColor hwColor:@"#0CDEFD" alpha:1.0].CGColor, (__bridge NSString *)[UIColor hwColor:@"#058DFB" alpha:1.0].CGColor];
    gradientLayer.locations = @[@(0), @(1.0f)];
    [konwBut.layer addSublayer:gradientLayer];
    
    [konwBut mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(48);
        make.width.mas_equalTo(160.f);
        make.centerX.mas_equalTo(0.f);
        make.bottom.mas_equalTo(-30);
    }];
    
    
    UIButton *colseBut = [[UIButton alloc] init];
    [colseBut setImage:[UIImage imageNamed:@"common_del_white"] forState:UIControlStateNormal];
    [colseBut addTarget:self action:@selector(colseFun) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:colseBut];
    
    [colseBut mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(48);
        make.width.mas_equalTo(48.f);
        make.centerX.mas_equalTo(0.f);
        make.top.mas_equalTo(_whiteBgView.mas_bottom).offset(30);
    }];
}


- (void)colseFun
{
    NSString *datestr = [iTools getNowDateString];
    [HWDataManager setObjectWithKey:Const_did_show_image_version_date value:datestr];
    [self removeFromSuperview];
}

@end
