






#import "ArcadeSpellLabel.h"
#import "SafariFloor.h"
#import "UIImage+ArmImage.h"

@implementation ArcadeSpellLabel

+ (ArcadeSpellLabel *)caretExposureLabel {
    return [self caretExposureLabel:YES];
}

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

    NSAttributedString *tremorFilmStoneAsteriskBasque = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage minderPointerInsulinContrastBackwardsName:SafariFloor.wakeTrustDay.stepMomentRareKeepSortSubscript] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        tremorFilmStoneAsteriskBasque = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = SafariFloor.issueExecSlide.duplexEnergy;
    NSMutableAttributedString *vortexNameWill = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange barOffExecFeet = [text rangeOfString:SafariFloor.issueExecSlide.flushedPrimary];
    if (barOffExecFeet.location != NSNotFound) {
        [vortexNameWill addAttribute:NSForegroundColorAttributeName value:[SafariFloor andVerifyColor] range:barOffExecFeet];
        [vortexNameWill addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:barOffExecFeet];
    }

    
    NSMutableAttributedString *hertzFlightsScrollingIntegrateObserving = [[NSMutableAttributedString alloc] init];
    if (tremorFilmStoneAsteriskBasque) {
        [hertzFlightsScrollingIntegrateObserving appendAttributedString:tremorFilmStoneAsteriskBasque];
    }
    [hertzFlightsScrollingIntegrateObserving appendAttributedString:vortexNameWill];
    
    label.attributedText = hertzFlightsScrollingIntegrateObserving;
    
    
    UITapGestureRecognizer *returnsRet = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(peerExtraCaptureEndsFeatured:)];
    [label addGestureRecognizer:returnsRet];
    
    return label;
}

- (void)setWalkMatrixFork:(BOOL)walkMatrixFork {
    _walkMatrixFork = !walkMatrixFork;
    [self sumUnloadSerifArtworkRegistryTailLabel:self];
}

- (void)peerExtraCaptureEndsFeatured:(UITapGestureRecognizer *)returnsRet {
    ArcadeSpellLabel *label = (ArcadeSpellLabel *)returnsRet.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 handPlugMap = [returnsRet locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint reversesStartDetectsLocallyCar = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint captionCapableEllipseWhileOrangeDevices = CGPointMake(
        handPlugMap.x - reversesStartDetectsLocallyCar.x,
        handPlugMap.y - reversesStartDetectsLocallyCar.y
    );
    
    
    __block BOOL sayAgeCurlIts = 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 rankedPlay;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&rankedPlay];
            
            
            CGRect quickRect = [layoutManager boundingRectForGlyphRange:rankedPlay
                                                      inTextContainer:textContainer];
            
            
            CGRect badOutSolidRect = CGRectOffset(quickRect, reversesStartDetectsLocallyCar.x, reversesStartDetectsLocallyCar.y);
            
            
            if (CGRectContainsPoint(badOutSolidRect, handPlugMap)) {
                sayAgeCurlIts = YES;
                *stop = YES;
            }
        }
    }];
    
    if (sayAgeCurlIts) {
        
        
        [self sumUnloadSerifArtworkRegistryTailLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:captionCapableEllipseWhileOrangeDevices
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *fillText = label.attributedText.string;
    NSRange barOffExecFeet = [fillText rangeOfString:SafariFloor.issueExecSlide.flushedPrimary];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, barOffExecFeet)) {
        
        
        if (self.narrativeOriginalRemovableFormIntegrateSuggest) {
            self.narrativeOriginalRemovableFormIntegrateSuggest();
        }
    }
}


- (void)sumUnloadSerifArtworkRegistryTailLabel:(ArcadeSpellLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL fixComplex = 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 thickLoss = !_walkMatrixFork;
        
        
        NSTextAttachment *relationsNear = [[NSTextAttachment alloc] init];
        
        
        UIColor *masterColor = thickLoss ? [SafariFloor andVerifyColor]: UIColor.lightGrayColor;
        UIImage *passVeryImage = [UIImage minderPointerInsulinContrastBackwardsName:thickLoss ? SafariFloor.wakeTrustDay.figureDanishIrishDecideServicesLongest :SafariFloor.wakeTrustDay.stepMomentRareKeepSortSubscript];
        
        
        relationsNear.image = [[passVeryImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:masterColor];
        relationsNear.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:relationsNear range:range];
        
        _walkMatrixFork = thickLoss;
        fixComplex = YES;
        *stop = YES;
    }];
    
    if (fixComplex) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
