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

#import "FtCjhxInfoDialog.h"

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

@end

@implementation FtCjhxInfoDialog

- (instancetype)initWithTitle:(NSString *)btnTitle  btnYes:(btnYes)btnYes btnNo:(btnNo)btnNo{
    self = [super init];
    if (self) {
        self.topTitle = btnTitle;
        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, 50 * WIDTHRADIU*10);
    self.contentView.center = self.center;
    [self addSubview:self.contentView];
    self.contentView.backgroundColor = [UIColor whiteColor];
    self.contentView.layer.cornerRadius = 5 * WIDTHRADIU;
    
    //标题title
    UILabel *lb_title = [UILabel new];
    lb_title.text = self.topTitle;
    lb_title.font = [UIFont systemFontOfSize:22 * WIDTHRADIU weight:UIFontWeightMedium];
    lb_title.textAlignment = NSTextAlignmentCenter;
    lb_title.textColor = [UIColor colorWithHex:0x4c4c4c];
    [self.contentView addSubview:lb_title];
    [lb_title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(25 * WIDTHRADIU);
        make.centerX.equalTo(self.contentView);
    }];
    
    //窗体主内容
    //NSString *msg=@"为了更好的保护您的权益,在此为您介绍\n在基金开户和交易服务过程中我们将如\n何规范安全的收集、存储以及使用您的\n信息,请您充分了解:为了正常识别手机\n设备和运营商号码、保证您的账号和资金\n安全,需要您授权设备信息和手机号码。";
    NSString*msg=@"为向您提供更便捷的开户服务体验,看看\n生活将会向我们(创金合信基金管理有限\n公司,联系方式400-868-0666)提供您的\n身份证正反面,姓名、身份证号码、职业\n类型、居住地址，信息将仅用作基金开户\n预填,不会自动开立基金账号,也不会对\n您的权益产生不利影响。\n\n如果您点击同意,表示同意提供,如果您\n点击不同意,不会影响您使用我们的其他\n服务,开户信息需由您自主上传。";
    UILabel *lb_message = [UILabel new];
    NSMutableParagraphStyle *style = [NSMutableParagraphStyle new];
    style.lineSpacing = 10;
    style.lineBreakMode = NSLineBreakByTruncatingTail;
    NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:msg];
    [attrString addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, msg.length)];
    lb_message.attributedText = attrString;
    lb_message.text =msg;
    //lb_message.bounds=CGRectMake(0, 0, ScreenWidth/5*4, ScreenHeight/10*3);
    lb_message.font = [UIFont systemFontOfSize:17 * WIDTHRADIU];
    lb_message.textAlignment = NSTextAlignmentCenter;
    lb_message.textColor = [UIColor colorWithHex:0x505050];
    lb_message.lineBreakMode=UILineBreakModeWordWrap;
    lb_message.numberOfLines=0;
    [self.contentView addSubview:lb_message];
    [lb_message mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lb_title.mas_bottom).offset(10 * WIDTHRADIU);
        make.centerX.equalTo(self.contentView);
    }];
    
    //协议01
//    UIButton *text01 = [UIButton buttonWithType:UIButtonTypeCustom];
//    [text01 setTitle:@"《创金合信基金电子直销平台隐私政策》" forState:UIControlStateNormal];
//    [text01 setTitleColor:[UIColor colorWithHex:0x086cd6] forState:UIControlStateNormal];
//    text01.titleLabel.font = [UIFont systemFontOfSize:14 * WIDTHRADIU];
//    text01.backgroundColor = [UIColor whiteColor];
//    [text01 addTarget:self action:@selector(text01Click:) forControlEvents:UIControlEventTouchUpInside];
//    [self.contentView addSubview:text01];
//    [text01 mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(lb_message.mas_bottom).offset(18 * WIDTHRADIU);
//        make.left.equalTo(self.contentView);
//    }];
//
//    //协议02
//    UIButton *text02 = [UIButton buttonWithType:UIButtonTypeCustom];
//    [text02 setTitle:@"《创金合信基金个人信息使用授权书》" forState:UIControlStateNormal];
//    [text02 setTitleColor:[UIColor colorWithHex:0x086cd6] forState:UIControlStateNormal];
//    text02.titleLabel.font = [UIFont systemFontOfSize:14 * WIDTHRADIU];
//    text02.backgroundColor = [UIColor whiteColor];
//    [text02 addTarget:self action:@selector(text02Click:) forControlEvents:UIControlEventTouchUpInside];
//    [self.contentView addSubview:text02];
//    [text02 mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(text01.mas_bottom).offset(12 * WIDTHRADIU);
//        make.left.equalTo(self.contentView);
//    }];
    
    //同意按钮
    UIButton *confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [confirmBtn setTitle:@"同意" forState:UIControlStateNormal];
    [confirmBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    confirmBtn.titleLabel.font = [UIFont systemFontOfSize:17 * WIDTHRADIU];
    confirmBtn.backgroundColor = [UIColor colorWithHex:0xFF3A2E];
    confirmBtn.layer.cornerRadius = 5 * WIDTHRADIU;
    confirmBtn.layer.masksToBounds = YES;
    [confirmBtn addTarget:self action:@selector(btnYes:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:confirmBtn];
    [confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lb_message.mas_bottom).offset(20 * WIDTHRADIU);
        make.centerX.equalTo(self.contentView);
        make.width.offset(ScreenWidth/20*17-40*WIDTHRADIU);
        make.height.offset(50 * WIDTHRADIU);
    }];
    
    //不同意
    UILabel *textNo = [UILabel new];
    textNo.text =@"不同意";
    textNo.font = [UIFont systemFontOfSize:16 * WIDTHRADIU weight:UIFontWeightMedium];
    textNo.userInteractionEnabled=YES;
    UITapGestureRecognizer *tapText03 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(btnNo:)];
    [textNo addGestureRecognizer:tapText03];
    //text01.textAlignment = NSTextAlignmentCenter;
    textNo.textColor = [UIColor colorWithHex:0x505050];
    [self.contentView addSubview:textNo];
    [textNo mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(confirmBtn.mas_bottom).offset(15*WIDTHRADIU);
        make.centerX.equalTo(self.contentView);
    }];
    
}


//-(void)text01Click:(UIButton *)sender{
//    if (self.table01) {
//        self.table01();
//    }
//    
//}
//
//
//
//-(void)text02Click:(UIButton *)sender{
//    if (self.table02) {
//        self.table02();
//    }
//    
//}

-(void)btnYes:(UIButton *)sender{
    if (self.btnYes) {
        self.btnYes();
    }
    [self dismissUI];
    
}
-(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{
    
    FtCjhxInfoDialog *alertView = [[FtCjhxInfoDialog 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
