






#import "SphereRightLabel.h"
#import "PutBelowEye.h"
#import "UIImage+DidImage.h"

@implementation SphereRightLabel

+ (SphereRightLabel *)logWasLogicalLabel {
    return [self logWasLogicalLabel:YES];
}

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

    NSAttributedString *ownYouIgnoredCaseBlob = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage unsignedTableRenewExcludedSlabName:PutBelowEye.yetRevealHow.assameseCathedralIdleNoticeRecognizeSecurely] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        ownYouIgnoredCaseBlob = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = PutBelowEye.listColumnRoot.waxEsperanto;
    NSMutableAttributedString *assignStandard = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange topYouMileLazy = [text rangeOfString:PutBelowEye.listColumnRoot.flipMakeArtDry];
    if (topYouMileLazy.location != NSNotFound) {
        [assignStandard addAttribute:NSForegroundColorAttributeName value:[PutBelowEye charAlienColor] range:topYouMileLazy];
        [assignStandard addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:topYouMileLazy];
    }

    
    NSMutableAttributedString *hoverWaxMoreGujaratiSetup = [[NSMutableAttributedString alloc] init];
    if (ownYouIgnoredCaseBlob) {
        [hoverWaxMoreGujaratiSetup appendAttributedString:ownYouIgnoredCaseBlob];
    }
    [hoverWaxMoreGujaratiSetup appendAttributedString:assignStandard];
    
    label.attributedText = hoverWaxMoreGujaratiSetup;
    
    
    UITapGestureRecognizer *uploadAtom = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(pullHailKitOutlineVowel:)];
    [label addGestureRecognizer:uploadAtom];
    
    return label;
}

- (void)setEnergyAsterisk:(BOOL)energyAsterisk {
    _energyAsterisk = !energyAsterisk;
    [self failureCorrectedMostlyStreamsDrainActualLabel:self];
}

- (void)pullHailKitOutlineVowel:(UITapGestureRecognizer *)uploadAtom {
    SphereRightLabel *label = (SphereRightLabel *)uploadAtom.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 oddPlayback = [uploadAtom locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint signalBendObjectDailyRecorded = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint offsetsLexicalBigMenEpsilonAuxiliary = CGPointMake(
        oddPlayback.x - signalBendObjectDailyRecorded.x,
        oddPlayback.y - signalBendObjectDailyRecorded.y
    );
    
    
    __block BOOL scheduledTake = 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 seeBandHue;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&seeBandHue];
            
            
            CGRect everyRect = [layoutManager boundingRectForGlyphRange:seeBandHue
                                                      inTextContainer:textContainer];
            
            
            CGRect dogSleetSobRect = CGRectOffset(everyRect, signalBendObjectDailyRecorded.x, signalBendObjectDailyRecorded.y);
            
            
            if (CGRectContainsPoint(dogSleetSobRect, oddPlayback)) {
                scheduledTake = YES;
                *stop = YES;
            }
        }
    }];
    
    if (scheduledTake) {
        
        
        [self failureCorrectedMostlyStreamsDrainActualLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:offsetsLexicalBigMenEpsilonAuxiliary
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *typeText = label.attributedText.string;
    NSRange topYouMileLazy = [typeText rangeOfString:PutBelowEye.listColumnRoot.flipMakeArtDry];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, topYouMileLazy)) {
        
        
        if (self.powerLinkCompoundDiagnoseDatumSeventeen) {
            self.powerLinkCompoundDiagnoseDatumSeventeen();
        }
    }
}


- (void)failureCorrectedMostlyStreamsDrainActualLabel:(SphereRightLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL illegalSpa = 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 filterBit = !_energyAsterisk;
        
        
        NSTextAttachment *areCapSpanish = [[NSTextAttachment alloc] init];
        
        
        UIColor *spokenColor = filterBit ? [PutBelowEye charAlienColor]: UIColor.lightGrayColor;
        UIImage *rowFocusImage = [UIImage unsignedTableRenewExcludedSlabName:filterBit ? PutBelowEye.yetRevealHow.embeddedPashtoSpeakersEvaluateForceBlock :PutBelowEye.yetRevealHow.assameseCathedralIdleNoticeRecognizeSecurely];
        
        
        areCapSpanish.image = [[rowFocusImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:spokenColor];
        areCapSpanish.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:areCapSpanish range:range];
        
        _energyAsterisk = filterBit;
        illegalSpa = YES;
        *stop = YES;
    }];
    
    if (illegalSpa) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
