






#import "ScoreHisRawLabel.h"
#import "BestSharpen.h"
#import "UIImage+LogImage.h"

@implementation ScoreHisRawLabel

+ (ScoreHisRawLabel *)listTrackHairLabel {
    return [self listTrackHairLabel:YES];
}

+ (ScoreHisRawLabel *)listTrackHairLabel:(BOOL)isCheckBox {
    
    ScoreHisRawLabel *label = [[ScoreHisRawLabel alloc] init];
    label.numberOfLines = 0;
    label.textAlignment = NSTextAlignmentCenter;
    label.textColor = [UIColor lightGrayColor];
    label.font = [UIFont systemFontOfSize:12];
    label.userInteractionEnabled = YES; 

    NSAttributedString *affiliateOutSynthesisAskHurricane = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage weeklyReportingBirthRevisionsOffName:BestSharpen.didNapCoptic.regularCountedSafariCheckedBookProjects] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        affiliateOutSynthesisAskHurricane = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = BestSharpen.hangFillerPick.nonceProduct;
    NSMutableAttributedString *rowBestTakeSum = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange resizeLiveUnit = [text rangeOfString:BestSharpen.hangFillerPick.addAskBadTable];
    if (resizeLiveUnit.location != NSNotFound) {
        [rowBestTakeSum addAttribute:NSForegroundColorAttributeName value:[BestSharpen sawExportColor] range:resizeLiveUnit];
        [rowBestTakeSum addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:resizeLiveUnit];
    }

    
    NSMutableAttributedString *performsKeyboardSpouseDropAsterisk = [[NSMutableAttributedString alloc] init];
    if (affiliateOutSynthesisAskHurricane) {
        [performsKeyboardSpouseDropAsterisk appendAttributedString:affiliateOutSynthesisAskHurricane];
    }
    [performsKeyboardSpouseDropAsterisk appendAttributedString:rowBestTakeSum];
    
    label.attributedText = performsKeyboardSpouseDropAsterisk;
    
    
    UITapGestureRecognizer *homeRedOwn = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(pitchBrownDiscountsBitmapPlus:)];
    [label addGestureRecognizer:homeRedOwn];
    
    return label;
}

- (void)setShadowReferent:(BOOL)shadowReferent {
    _shadowReferent = !shadowReferent;
    [self percentKnowSpanishMoveFunctionProvideLabel:self];
}

- (void)pitchBrownDiscountsBitmapPlus:(UITapGestureRecognizer *)homeRedOwn {
    ScoreHisRawLabel *label = (ScoreHisRawLabel *)homeRedOwn.view;
    if (!label.attributedText) return;
    
    
    NSTextStorage *textStorage = [[NSTextStorage alloc] initWithAttributedString:label.attributedText];
    NSLayoutManager *layoutManager = [[NSLayoutManager alloc] init];
    NSTextContainer *textContainer = [[NSTextContainer alloc] initWithSize:label.bounds.size];
    
    textContainer.lineFragmentPadding = 0;
    textContainer.maximumNumberOfLines = label.numberOfLines;
    textContainer.lineBreakMode = label.lineBreakMode;
    
    [textStorage addLayoutManager:layoutManager];
    [layoutManager addTextContainer:textContainer];
    
    
    [layoutManager ensureLayoutForTextContainer:textContainer];
    
    
    CGPoint consumesSay = [homeRedOwn locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint megawattsProtocolsCaseDarkPretty = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint speakersFormatsPrologResizeSeparatorFast = CGPointMake(
        consumesSay.x - megawattsProtocolsCaseDarkPretty.x,
        consumesSay.y - megawattsProtocolsCaseDarkPretty.y
    );
    
    
    __block BOOL slabBookSplat = NO;
    [label.attributedText enumerateAttribute:NSAttachmentAttributeName
                                    inRange:NSMakeRange(0, label.attributedText.length)
                                    options:0
                                 usingBlock:^(id value, NSRange range, BOOL *stop) {
        if ([value isKindOfClass:[NSTextAttachment class]]) {
            
            NSRange binSawPlug;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&binSawPlug];
            
            
            CGRect burstRect = [layoutManager boundingRectForGlyphRange:binSawPlug
                                                      inTextContainer:textContainer];
            
            
            CGRect outGujaratiRect = CGRectOffset(burstRect, megawattsProtocolsCaseDarkPretty.x, megawattsProtocolsCaseDarkPretty.y);
            
            
            if (CGRectContainsPoint(outGujaratiRect, consumesSay)) {
                slabBookSplat = YES;
                *stop = YES;
            }
        }
    }];
    
    if (slabBookSplat) {
        
        
        [self percentKnowSpanishMoveFunctionProvideLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:speakersFormatsPrologResizeSeparatorFast
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *fairText = label.attributedText.string;
    NSRange resizeLiveUnit = [fairText rangeOfString:BestSharpen.hangFillerPick.addAskBadTable];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, resizeLiveUnit)) {
        
        
        if (self.capacityUnitRespondFarsiOpenIncrement) {
            self.capacityUnitRespondFarsiOpenIncrement();
        }
    }
}


- (void)percentKnowSpanishMoveFunctionProvideLabel:(ScoreHisRawLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL armGlucose = NO;
    
    [attributedText enumerateAttribute:NSAttachmentAttributeName
                             inRange:NSMakeRange(0, attributedText.length)
                             options:0
                          usingBlock:^(NSTextAttachment *oldAttachment, NSRange range, BOOL *stop) {
        if (![oldAttachment isKindOfClass:[NSTextAttachment class]]) return;
        
        
        BOOL replyCase = !_shadowReferent;
        
        
        NSTextAttachment *irregularTrap = [[NSTextAttachment alloc] init];
        
        
        UIColor *funnelColor = replyCase ? [BestSharpen sawExportColor]: UIColor.lightGrayColor;
        UIImage *armNoiseImage = [UIImage weeklyReportingBirthRevisionsOffName:replyCase ? BestSharpen.didNapCoptic.quotesPrepareSubtitlesEggLettersReached :BestSharpen.didNapCoptic.regularCountedSafariCheckedBookProjects];
        
        
        irregularTrap.image = [[armNoiseImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:funnelColor];
        irregularTrap.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:irregularTrap range:range];
        
        _shadowReferent = replyCase;
        armGlucose = YES;
        *stop = YES;
    }];
    
    if (armGlucose) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
