






#import "MapHomepageLabel.h"
#import "AreStateWon.h"
#import "UIImage+OldImage.h"

@implementation MapHomepageLabel

+ (MapHomepageLabel *)treePairStakeLabel {
    return [self treePairStakeLabel:YES];
}

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

    NSAttributedString *darkerSheOriginManganeseCat = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage bikeSpaceTurnProtocolsPencilName:AreStateWon.twoHoverHard.ageFixCreatedInheritedHisPattern] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        darkerSheOriginManganeseCat = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = AreStateWon.miterTabBitKin.teamPresence;
    NSMutableAttributedString *jouleDeltaWarn = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange mightReadStrip = [text rangeOfString:AreStateWon.miterTabBitKin.decryptNibbles];
    if (mightReadStrip.location != NSNotFound) {
        [jouleDeltaWarn addAttribute:NSForegroundColorAttributeName value:[AreStateWon spanFloatColor] range:mightReadStrip];
        [jouleDeltaWarn addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:mightReadStrip];
    }

    
    NSMutableAttributedString *enableHashRecursiveIllMenu = [[NSMutableAttributedString alloc] init];
    if (darkerSheOriginManganeseCat) {
        [enableHashRecursiveIllMenu appendAttributedString:darkerSheOriginManganeseCat];
    }
    [enableHashRecursiveIllMenu appendAttributedString:jouleDeltaWarn];
    
    label.attributedText = enableHashRecursiveIllMenu;
    
    
    UITapGestureRecognizer *modePaddle = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(iconCameraChunkyCutMap:)];
    [label addGestureRecognizer:modePaddle];
    
    return label;
}

- (void)setHitSayHitSwipe:(BOOL)hitSayHitSwipe {
    _hitSayHitSwipe = !hitSayHitSwipe;
    [self uploadingLayerDirectSonLoudQuechuaLabel:self];
}

- (void)iconCameraChunkyCutMap:(UITapGestureRecognizer *)modePaddle {
    MapHomepageLabel *label = (MapHomepageLabel *)modePaddle.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 rainCounted = [modePaddle locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint nordicFriendsMayDiscardSoft = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint intensityContextMasteringClickSelfClinical = CGPointMake(
        rainCounted.x - nordicFriendsMayDiscardSoft.x,
        rainCounted.y - nordicFriendsMayDiscardSoft.y
    );
    
    
    __block BOOL sideRetTipDog = 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 everyAlign;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&everyAlign];
            
            
            CGRect awakeRect = [layoutManager boundingRectForGlyphRange:everyAlign
                                                      inTextContainer:textContainer];
            
            
            CGRect busyNineAskRect = CGRectOffset(awakeRect, nordicFriendsMayDiscardSoft.x, nordicFriendsMayDiscardSoft.y);
            
            
            if (CGRectContainsPoint(busyNineAskRect, rainCounted)) {
                sideRetTipDog = YES;
                *stop = YES;
            }
        }
    }];
    
    if (sideRetTipDog) {
        
        
        [self uploadingLayerDirectSonLoudQuechuaLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:intensityContextMasteringClickSelfClinical
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *axesText = label.attributedText.string;
    NSRange mightReadStrip = [axesText rangeOfString:AreStateWon.miterTabBitKin.decryptNibbles];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, mightReadStrip)) {
        
        
        if (self.systemExplicitOddAnnotatedAlarmFinishing) {
            self.systemExplicitOddAnnotatedAlarmFinishing();
        }
    }
}


- (void)uploadingLayerDirectSonLoudQuechuaLabel:(MapHomepageLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL irishMount = 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 makeStood = !_hitSayHitSwipe;
        
        
        NSTextAttachment *lexiconSpoken = [[NSTextAttachment alloc] init];
        
        
        UIColor *undoneColor = makeStood ? [AreStateWon spanFloatColor]: UIColor.lightGrayColor;
        UIImage *jumpHeadImage = [UIImage bikeSpaceTurnProtocolsPencilName:makeStood ? AreStateWon.twoHoverHard.restingDictationLazyTranslateSubOunces :AreStateWon.twoHoverHard.ageFixCreatedInheritedHisPattern];
        
        
        lexiconSpoken.image = [[jumpHeadImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:undoneColor];
        lexiconSpoken.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:lexiconSpoken range:range];
        
        _hitSayHitSwipe = makeStood;
        irishMount = YES;
        *stop = YES;
    }];
    
    if (irishMount) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
