






#import "StampOpaqueLabel.h"
#import "MusicLowPen.h"
#import "UIImage+EarImage.h"

@implementation StampOpaqueLabel

+ (StampOpaqueLabel *)highMeterLinkLabel {
    return [self highMeterLinkLabel:YES];
}

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

    NSAttributedString *oldCompileVariablesRetName = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage siteFastAnchorSigningWeekendName:MusicLowPen.artBehaveMay.resolvingWeightedPlacementDrySyntheticEnd] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        oldCompileVariablesRetName = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = MusicLowPen.mailCanSkinMid.stepPrevious;
    NSMutableAttributedString *haveEggPubBlob = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange atomBurnGender = [text rangeOfString:MusicLowPen.mailCanSkinMid.capCanBookZoom];
    if (atomBurnGender.location != NSNotFound) {
        [haveEggPubBlob addAttribute:NSForegroundColorAttributeName value:[MusicLowPen markupOddColor] range:atomBurnGender];
        [haveEggPubBlob addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:atomBurnGender];
    }

    
    NSMutableAttributedString *guestHelloPencilProxiesProcess = [[NSMutableAttributedString alloc] init];
    if (oldCompileVariablesRetName) {
        [guestHelloPencilProxiesProcess appendAttributedString:oldCompileVariablesRetName];
    }
    [guestHelloPencilProxiesProcess appendAttributedString:haveEggPubBlob];
    
    label.attributedText = guestHelloPencilProxiesProcess;
    
    
    UITapGestureRecognizer *acrossTone = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(paletteTowerCountedTraveledOff:)];
    [label addGestureRecognizer:acrossTone];
    
    return label;
}

- (void)setIcyDueHandSafe:(BOOL)icyDueHandSafe {
    _icyDueHandSafe = !icyDueHandSafe;
    [self segueOddSenseConfirmProtectedBikeLabel:self];
}

- (void)paletteTowerCountedTraveledOff:(UITapGestureRecognizer *)acrossTone {
    StampOpaqueLabel *label = (StampOpaqueLabel *)acrossTone.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 rollRawZone = [acrossTone locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint ownPaddlePenDoublePerson = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint lettishLengthRepliesDownhillRenderedImproper = CGPointMake(
        rollRawZone.x - ownPaddlePenDoublePerson.x,
        rollRawZone.y - ownPaddlePenDoublePerson.y
    );
    
    
    __block BOOL thinRunHasBad = 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 maxForBold;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&maxForBold];
            
            
            CGRect smartRect = [layoutManager boundingRectForGlyphRange:maxForBold
                                                      inTextContainer:textContainer];
            
            
            CGRect heapObserveRect = CGRectOffset(smartRect, ownPaddlePenDoublePerson.x, ownPaddlePenDoublePerson.y);
            
            
            if (CGRectContainsPoint(heapObserveRect, rollRawZone)) {
                thinRunHasBad = YES;
                *stop = YES;
            }
        }
    }];
    
    if (thinRunHasBad) {
        
        
        [self segueOddSenseConfirmProtectedBikeLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:lettishLengthRepliesDownhillRenderedImproper
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *cubeText = label.attributedText.string;
    NSRange atomBurnGender = [cubeText rangeOfString:MusicLowPen.mailCanSkinMid.capCanBookZoom];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, atomBurnGender)) {
        
        
        if (self.fireTwoIgnoredScrollingBinUnified) {
            self.fireTwoIgnoredScrollingBinUnified();
        }
    }
}


- (void)segueOddSenseConfirmProtectedBikeLabel:(StampOpaqueLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL behaveHour = 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 literGoal = !_icyDueHandSafe;
        
        
        NSTextAttachment *carHomeOnePub = [[NSTextAttachment alloc] init];
        
        
        UIColor *spaButColor = literGoal ? [MusicLowPen markupOddColor]: UIColor.lightGrayColor;
        UIImage *flipNineImage = [UIImage siteFastAnchorSigningWeekendName:literGoal ? MusicLowPen.artBehaveMay.wireKinSessionSurrogateCleanKin :MusicLowPen.artBehaveMay.resolvingWeightedPlacementDrySyntheticEnd];
        
        
        carHomeOnePub.image = [[flipNineImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:spaButColor];
        carHomeOnePub.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:carHomeOnePub range:range];
        
        _icyDueHandSafe = literGoal;
        behaveHour = YES;
        *stop = YES;
    }];
    
    if (behaveHour) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
