//
//  AlertView.m
//  Open
//
//  Created by 雷俊博 on 2019/7/22.
//  Copyright © 2019 黄江涛 . All rights reserved.
//

#import "AlertView.h"
#import "Constants.h"

@interface AlertView ()

@property (nonatomic, strong)UIImageView *imgView_top;

@property (nonatomic, strong)UILabel *lb_middle;

@property (nonatomic, strong)UIView *lineViewH;

@property (nonatomic, strong)UIButton* btn_left;

@property (nonatomic, strong)UIView *lineViewV;

@property (nonatomic, strong)UIButton *btn_right;

@end
@implementation AlertView
#pragma mark - life cycle
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self addSubview:self.imgView_top];
        [self addSubview:self.lb_middle];
        [self addSubview:self.lineViewH];
        [self addSubview:self.btn_left];
        [self addSubview:self.lineViewV];
        [self addSubview:self.btn_right];
        self.layer.cornerRadius = 10 * WIDTHRADIU;
        self.layer.masksToBounds = YES;
        [self setupUI];
    }
    
    return self;
}
- (void)setupUI
{
    [self.imgView_top mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.centerX.equalTo(self);
        make.top.offset(12 * WIDTHRADIU);
        make.width.height.offset(51 * WIDTHRADIU);
    }];
    
    [self.lb_middle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.imgView_top.mas_bottom).offset(10 * WIDTHRADIU);
        make.centerX.equalTo(self);
        make.height.offset(35 * WIDTHRADIU);
    }];
    
    [self.lineViewH mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.lb_middle.mas_bottom).offset(10 * WIDTHRADIU);
        make.left.right.offset(0);
        make.height.offset(1);
    }];
    
    [self.lineViewV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.lineViewH.mas_bottom);
        make.bottom.offset(0);
        make.width.offset(1);
        make.centerX.equalTo(self);
    }];
    
    [self.btn_left mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.lineViewH.mas_bottom);
        make.left.offset(0);
        make.right.equalTo(self.lineViewV.mas_left);
        make.bottom.offset(0);
    }];
    [self.btn_right mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.lineViewH.mas_bottom);
        make.right.offset(0);
        make.left.equalTo(self.lineViewV.mas_right);
        make.bottom.offset(0);
    }];
}


#pragma mark - event reponse
- (void)btnClick:(UIButton *)btn
{
    if (self.canceSureActionBlock) {
        self.canceSureActionBlock(btn.tag);
    }
}

#pragma mark - gettrs and setters;
- (UIImageView *)imgView_top
{
    if (!_imgView_top) {
        _imgView_top = [[UIImageView alloc]init];
        _imgView_top.image = [UIImage imageNamed:@"Certification_failure_Cryingface_normal"];
    }
    return _imgView_top;
}

- (UILabel *)lb_middle
{
    if (!_lb_middle) {
        _lb_middle = [[UILabel alloc]init];
        _lb_middle.text = @"认证失败,请重新认证\n或提交人工审核";
        _lb_middle.font = [UIFont systemFontOfSize:14 * WIDTHRADIU];
        _lb_middle.textColor = [UIColor colorWithHex:0x4c4c4c];
        _lb_middle.textAlignment = NSTextAlignmentCenter;
        _lb_middle.numberOfLines = 2;
    }
    return _lb_middle;
}

- (UIView *)lineViewH
{
    if (!_lineViewH) {
        _lineViewH = [[UIView alloc]init];
        _lineViewH.backgroundColor = [UIColor colorWithHex:0xd9d9d9];
    }
    return _lineViewH;
}

- (UIButton *)btn_left
{
    if (!_btn_left) {
        _btn_left = [UIButton buttonWithType:UIButtonTypeCustom];
        [_btn_left setTitle:@"人工审核" forState:UIControlStateNormal];
        _btn_left.titleLabel.font = [UIFont systemFontOfSize:14 * WIDTHRADIU];
        [_btn_left setTitleColor:K_MainColor forState:UIControlStateNormal];
        _btn_left.backgroundColor = [UIColor whiteColor];
        _btn_left.tag = 200;
        [_btn_left addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _btn_left;
}

- (UIView *)lineViewV
{
    if (!_lineViewV) {
        _lineViewV = [[UIView alloc]init];
        _lineViewV.backgroundColor = [UIColor colorWithHex:0xd9d9d9];
    }
    return _lineViewV;
}

- (UIButton *)btn_right
{
    if (!_btn_right) {
        _btn_right = [UIButton buttonWithType:UIButtonTypeCustom];
        [_btn_right setTitle:@"重新认证" forState:UIControlStateNormal];
        _btn_right.titleLabel.font = [UIFont systemFontOfSize:14 * WIDTHRADIU];
        [_btn_right setTitleColor:K_MainColor forState:UIControlStateNormal];
        _btn_right.backgroundColor = [UIColor whiteColor];
        _btn_right.tag = 201;
        [_btn_right addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _btn_right;
}

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

@end
