//
//  AgreeFootView.m
//  Open
//
//  Created by 雷俊博 on 2020/1/7.
//  Copyright © 2020 黄江涛 . All rights reserved.
//

#import "AgreeFootView.h"
#import <YYText.h>
#import "UIView+frameAdjust.h"

@interface AgreeFootView ()
{
    CGFloat margin;
    NSString* agreementText;
}

@property (nonatomic, strong)YYLabel *agreementLabel;

@end

@implementation AgreeFootView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        margin = 10;
        agreementText = @"点击同意即表示您已阅读并同意《看看生活用户协议》与《看看生活隐私政策》";
        self.agreementLabel = [[YYLabel alloc]init];
        [self setUI];
    }
    return self;
}

- (void)setUI
{
    NSMutableAttributedString* text = [[NSMutableAttributedString alloc]initWithString:agreementText];
       text.yy_lineSpacing = 5;
       text.yy_font = [UIFont systemFontOfSize:15];
       text.yy_color = [UIColor blackColor];
    
    [text yy_setTextHighlightRange:NSMakeRange(14, 10) color:[UIColor blueColor] backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
        if (self.delegate && [self.delegate respondsToSelector:@selector(userProtocolClick)]) {
            [self.delegate userProtocolClick];
        }
    }];
    
    
    [text yy_setTextHighlightRange:NSMakeRange(agreementText.length - 10, 10) color:[UIColor blueColor] backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
        if (self.delegate && [self.delegate respondsToSelector:@selector(privateProtocolClick)]) {
                   [self.delegate privateProtocolClick];
               }
    }];
    
    _agreementLabel.numberOfLines = 0;
    _agreementLabel.preferredMaxLayoutWidth = self.width - 2 * margin;
    _agreementLabel.attributedText = text;
    [self addSubview:_agreementLabel];
    [_agreementLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
}

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

@end
