






#import "GainLostFarLabel.h"
#import "RowGivenOut.h"
#import "UIImage+TopImage.h"

@implementation GainLostFarLabel

+ (GainLostFarLabel *)logoRedoAlertLabel {
    return [self logoRedoAlertLabel:YES];
}

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

    NSAttributedString *liftSpecifierDarkBarClean = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage guideTabTruncatedDoneMeterName:RowGivenOut.mathProxyKin.concertPongSmoothingWhiteVitalityCaution] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        liftSpecifierDarkBarClean = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = RowGivenOut.nineHisSoloTen.orderRetZero;
    NSMutableAttributedString *typePenHitAxes = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange greekLowCutIcy = [text rangeOfString:RowGivenOut.nineHisSoloTen.signSexTrapMin];
    if (greekLowCutIcy.location != NSNotFound) {
        [typePenHitAxes addAttribute:NSForegroundColorAttributeName value:[RowGivenOut drainBackColor] range:greekLowCutIcy];
        [typePenHitAxes addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:greekLowCutIcy];
    }

    
    NSMutableAttributedString *collapseSpringAxesAboutOther = [[NSMutableAttributedString alloc] init];
    if (liftSpecifierDarkBarClean) {
        [collapseSpringAxesAboutOther appendAttributedString:liftSpecifierDarkBarClean];
    }
    [collapseSpringAxesAboutOther appendAttributedString:typePenHitAxes];
    
    label.attributedText = collapseSpringAxesAboutOther;
    
    
    UITapGestureRecognizer *keepCourse = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(abortSequencerBurnWhoBond:)];
    [label addGestureRecognizer:keepCourse];
    
    return label;
}

- (void)setNormalPickSeed:(BOOL)normalPickSeed {
    _normalPickSeed = !normalPickSeed;
    [self itsTriangleEligibleGermanFunChestLabel:self];
}

- (void)abortSequencerBurnWhoBond:(UITapGestureRecognizer *)keepCourse {
    GainLostFarLabel *label = (GainLostFarLabel *)keepCourse.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 orangeMerge = [keepCourse locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint recursiveLongitudeBondPanoramaFrench = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint notBackwardsEarMaximumWinLossy = CGPointMake(
        orangeMerge.x - recursiveLongitudeBondPanoramaFrench.x,
        orangeMerge.y - recursiveLongitudeBondPanoramaFrench.y
    );
    
    
    __block BOOL destroyLookup = 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 escapeBlob;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&escapeBlob];
            
            
            CGRect tamilRect = [layoutManager boundingRectForGlyphRange:escapeBlob
                                                      inTextContainer:textContainer];
            
            
            CGRect nativeAvailRect = CGRectOffset(tamilRect, recursiveLongitudeBondPanoramaFrench.x, recursiveLongitudeBondPanoramaFrench.y);
            
            
            if (CGRectContainsPoint(nativeAvailRect, orangeMerge)) {
                destroyLookup = YES;
                *stop = YES;
            }
        }
    }];
    
    if (destroyLookup) {
        
        
        [self itsTriangleEligibleGermanFunChestLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:notBackwardsEarMaximumWinLossy
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *playText = label.attributedText.string;
    NSRange greekLowCutIcy = [playText rangeOfString:RowGivenOut.nineHisSoloTen.signSexTrapMin];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, greekLowCutIcy)) {
        
        
        if (self.andDrizzleHighSpacingFinishingDivider) {
            self.andDrizzleHighSpacingFinishingDivider();
        }
    }
}


- (void)itsTriangleEligibleGermanFunChestLabel:(GainLostFarLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL waistAlpha = 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 crossSort = !_normalPickSeed;
        
        
        NSTextAttachment *markSumAirMan = [[NSTextAttachment alloc] init];
        
        
        UIColor *hisManColor = crossSort ? [RowGivenOut drainBackColor]: UIColor.lightGrayColor;
        UIImage *canadianImage = [UIImage guideTabTruncatedDoneMeterName:crossSort ? RowGivenOut.mathProxyKin.gaspHerMarkAddRectifiedSlider :RowGivenOut.mathProxyKin.concertPongSmoothingWhiteVitalityCaution];
        
        
        markSumAirMan.image = [[canadianImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:hisManColor];
        markSumAirMan.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:markSumAirMan range:range];
        
        _normalPickSeed = crossSort;
        waistAlpha = YES;
        *stop = YES;
    }];
    
    if (waistAlpha) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
