//
//  FtCjhxDialog.m
//  Open
//
//  Created by weface on 2023/6/9.
//  Copyright © 2023 QXY. All rights reserved.
//

#import "AuthSuccessEss.h"

@interface AuthSuccessEss ()<UIGestureRecognizerDelegate>
@property (nonatomic, strong)UIView *contentView;
@property (nonatomic, copy)btnYes btnYes;
@property (nonatomic, copy) btnNo btnNo;

@end

@implementation AuthSuccessEss

- (instancetype)initWithTitle:(NSString *)btnTitle btnYes:(btnYes)btnYes btnNo:(btnNo)btnNo{
    self = [super init];
    if (self) {
        self.btnYes = btnYes;
        self.btnNo = btnNo;
        [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:)];
    tap.delegate = self;
    [self addGestureRecognizer:tap];
    
    //------- 弹窗主内容 -------//
    self.contentView = [[UIView alloc] init];
    self.contentView.bounds = CGRectMake(0, 0, ScreenWidth/20*17, 40 * WIDTHRADIU*9.5);
    self.contentView.center = self.center;
    [self addSubview:self.contentView];
    //self.contentView.backgroundColor = [UIColor whiteColor];
    self.contentView.layer.cornerRadius = 5 * WIDTHRADIU;
    
    
    //顶部图片
    UIImageView *topImage=[UIImageView new];
    topImage.image  = [UIImage imageNamed:@"auth_success_ess"];
    topImage.userInteractionEnabled=YES;
    UITapGestureRecognizer *tapText03 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(btnNo:)];
    [topImage addGestureRecognizer:tapText03];
    [self.contentView addSubview:topImage];
    [topImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(25 * WIDTHRADIU);
        make.centerX.equalTo(self.contentView);
    }];
 
    
}
-(void)btnNo:(UITapGestureRecognizer *)tap{
    if (self.btnNo) {
        self.btnNo();
    }
    [self dismissUI];
}


#pragma mark - public methods,
+ (void)showWithTitle:(UINavigationController *) view:(NSString *)btnTitle btnYes:(btnYes)btnYes btnNo:(btnNo)btnNo{
    
    AuthSuccessEss *alertView = [[AuthSuccessEss alloc] initWithTitle: btnTitle btnYes:btnYes btnNo:btnNo];
    
    //UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
    
    [view.view addSubview:alertView];
}

//点击空白处
- (void)tapClick:(UITapGestureRecognizer *)tap {
    [self dismissUI];
}

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

#pragma mark - UIGestureRecognizerDelegate
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    if ([touch.view isDescendantOfView:self.contentView]) {
        return NO;
    }
    return YES;
}
@end
