//
//  KKGoldHouseActivityView.m
//  Open
//
//  Created by 雷俊博 on 2021/4/21.
//  Copyright © 2021 黄江涛 . All rights reserved.
//

#import "KKGoldHouseActivityView.h"
#import "HGOrientationLabel.h"

@interface KKGoldHouseActivityView ()

/** 弹窗主内容view */
@property (nonatomic,strong) UIView   *contentView;

@property (nonatomic, copy)KKGoldHouseActivityViewBtnBlock block;

@end

@implementation KKGoldHouseActivityView
- (instancetype)initWithBlock:(KKGoldHouseActivityViewBtnBlock)block
{
    self = [super init];
    if (self) {
        self.block = block;
        
        [self setupUI];
    }
    return self;
}

- (void)setupUI
{
    self.frame = [UIScreen mainScreen].bounds;
    self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    //UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapClick:)];
    //[self addGestureRecognizer:tap];
    
    //------- 弹窗主内容 -------//
    self.contentView = [[UIView alloc] init];
    self.contentView.bounds = CGRectMake(0, 0, 277*WIDTHRADIU, 281 * WIDTHRADIU);
    self.contentView.center = self.center;
    [self addSubview:self.contentView];
    self.contentView.backgroundColor = [UIColor clearColor];
    //self.contentView.layer.cornerRadius = 15 * WIDTHRADIU;
    
    
    //顶部图片
    UIImageView*bgImg = [[UIImageView alloc]init];
    bgImg.image = [UIImage imageNamed:@"littleGoldHouse9999"];
    bgImg.frame = self.contentView.bounds;
    [self.contentView addSubview:bgImg];
    
    //标题
    HGOrientationLabel*lb_title = [[HGOrientationLabel alloc]initWithFrame:CGRectMake(75 * WIDTHRADIU, 18 * WIDTHRADIU, 127 * WIDTHRADIU, 40 * WIDTHRADIU)];
    lb_title.text = @"9999";
    lb_title.textColor = [UIColor whiteColor];
    lb_title.font = [UIFont systemFontOfSize:44 * WIDTHRADIU weight:UIFontWeightHeavy];
    lb_title.backgroundColor = [UIColor clearColor];
    [bgImg addSubview:lb_title];
    
    [lb_title textAlign:^(HGMaker *make) {
        make.addAlignType(textAlignType_center).addAlignType(textAlignType_bottom);
    }];
    
//    [lb_title mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerX.equalTo(self.contentView);
//        make.top.offset(18 * WIDTHRADIU);
//    }];
    
    HGOrientationLabel *lb_left = [HGOrientationLabel new];
    lb_left.text = @"免费\n赠您";
    lb_left.numberOfLines = 0;
    lb_left.textColor = [UIColor whiteColor];
    lb_left.font = [UIFont systemFontOfSize:18 * WIDTHRADIU weight:UIFontWeightRegular];
    [bgImg addSubview:lb_left];
    [lb_left textAlign:^(HGMaker *make) {
        make.addAlignType(textAlignType_center).addAlignType(textAlignType_bottom);
    }];
    [lb_left mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(lb_title);
        make.right.equalTo(lb_title.mas_left);
    }];
    
    HGOrientationLabel *lb_right = [HGOrientationLabel new];
    lb_right.text = @"金币";
    lb_right.textColor = [UIColor whiteColor];
    lb_right.font = [UIFont systemFontOfSize:18 * WIDTHRADIU weight:UIFontWeightRegular];
    [bgImg addSubview:lb_right];
    [lb_right textAlign:^(HGMaker *make) {
        make.addAlignType(textAlignType_center).addAlignType(textAlignType_bottom);
    }];
    [lb_right mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(lb_title);
        make.left.equalTo(lb_title.mas_right);
    }];
    
    //message
    UILabel*lb_message = [UILabel new];
    lb_message.text = @"“开户+存款”添加客服即可领取";
    lb_message.textColor = [UIColor whiteColor];
    lb_message.font = [UIFont systemFontOfSize:15 * WIDTHRADIU];
    [bgImg addSubview:lb_message];
    [lb_message mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.contentView);
        make.top.equalTo(lb_title.mas_bottom).offset(8 * WIDTHRADIU);
    }];
    
    
    
    
    UIButton* confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    confirmBtn.frame = CGRectMake(20 * WIDTHRADIU, 226 * WIDTHRADIU, 237 * WIDTHRADIU, 45 * WIDTHRADIU);
    CAGradientLayer *gradientLayer = [CAGradientLayer layer];
    gradientLayer.colors = @[(__bridge id)[UIColor colorWithHex:0xfedf6c].CGColor, (__bridge id)[UIColor colorWithHex:0xfdb21e].CGColor];
    gradientLayer.locations = @[@0.0, @1.0];
    gradientLayer.startPoint = CGPointMake(0, 0);
    gradientLayer.endPoint = CGPointMake(0.0, 1.0);
    gradientLayer.frame = confirmBtn.bounds;
    [confirmBtn.layer addSublayer:gradientLayer];
    
    [confirmBtn setTitle:@"领取方法" forState:UIControlStateNormal];
    [confirmBtn  setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    confirmBtn.titleLabel.font = [UIFont systemFontOfSize:16 * WIDTHRADIU];
    [confirmBtn addTarget:self action:@selector(confirmBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    //confirmBtn.backgroundColor = [UIColor colorWithHex:0xfbf7d4];
    [confirmBtn setTitleColor:[UIColor colorWithHex:0x801b1b] forState:UIControlStateNormal];
    confirmBtn.layer.cornerRadius = 22.5 * WIDTHRADIU;
    confirmBtn.layer.masksToBounds = YES;
    
    
    [self.contentView addSubview:confirmBtn];
    
    
    
    
    
    
    
    
    
    
    //关闭按钮
    UIButton*closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [closeBtn setImage:[UIImage imageNamed:@"btn_lottery_close"] forState:UIControlStateNormal];
    [closeBtn addTarget:self action:@selector(closeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:closeBtn];
    [closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_bottom).offset(20 * WIDTHRADIU);
        make.centerX.equalTo(self);
        make.width.height.offset(45 * WIDTHRADIU);
    }];
    
    
}

#pragma mark - 显示弹框
+ (void)showAlertViewWithVC:(UIViewController *)vc block:(KKGoldHouseActivityViewBtnBlock)block
{
    KKGoldHouseActivityView*baseView = [[KKGoldHouseActivityView alloc]initWithBlock:block];
    UIWindow* keyWindow = vc.view.window;
    
    if (keyWindow == nil) {
        keyWindow = [UIApplication sharedApplication].keyWindow;
    }

    [vc.view addSubview:baseView];
}

#pragma mark -隐藏弹框
- (void)dismissUI
{
     [self removeFromSuperview];
}


#pragma mark - event response
- (void)confirmBtnClick:(UIButton *)sender
{
    if (self.block) {
        self.block();
    }
    
    [self dismissUI];
}
- (void)closeBtnClick:(UIButton *)sender
{
    [self dismissUI];
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
