






#import "OldestAssetLabel.h"
#import "CityPublish.h"
#import "UIImage+EyeImage.h"

@implementation OldestAssetLabel

+ (OldestAssetLabel *)staleRestoresLabel {
    return [self staleRestoresLabel:YES];
}

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

    NSAttributedString *overlayProvisionHexRunAppending = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage extentsTenGroupDistortedTriggerName:CityPublish.halfInferCan.intervalDarkenSubscriptTurkmenResponderSource] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        overlayProvisionHexRunAppending = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = CityPublish.throughHosting.binArbitrary;
    NSMutableAttributedString *maleTagPushOld = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange floorAccording = [text rangeOfString:CityPublish.throughHosting.waxEndEarMight];
    if (floorAccording.location != NSNotFound) {
        [maleTagPushOld addAttribute:NSForegroundColorAttributeName value:[CityPublish audioRestColor] range:floorAccording];
        [maleTagPushOld addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:floorAccording];
    }

    
    NSMutableAttributedString *producesPashtoProposalCancelWho = [[NSMutableAttributedString alloc] init];
    if (overlayProvisionHexRunAppending) {
        [producesPashtoProposalCancelWho appendAttributedString:overlayProvisionHexRunAppending];
    }
    [producesPashtoProposalCancelWho appendAttributedString:maleTagPushOld];
    
    label.attributedText = producesPashtoProposalCancelWho;
    
    
    UITapGestureRecognizer *buttonPeak = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(moreRecordingRefusedReferentBank:)];
    [label addGestureRecognizer:buttonPeak];
    
    return label;
}

- (void)setSaltCurvePress:(BOOL)saltCurvePress {
    _saltCurvePress = !saltCurvePress;
    [self reloadDescribesTenTallTopArbiterLabel:self];
}

- (void)moreRecordingRefusedReferentBank:(UITapGestureRecognizer *)buttonPeak {
    OldestAssetLabel *label = (OldestAssetLabel *)buttonPeak.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 darkPinIron = [buttonPeak locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint spanSuccessPushTibetanLappish = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint twitterTildePredictedSentYearWon = CGPointMake(
        darkPinIron.x - spanSuccessPushTibetanLappish.x,
        darkPinIron.y - spanSuccessPushTibetanLappish.y
    );
    
    
    __block BOOL spaDefaultPub = 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 dogBusLead;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&dogBusLead];
            
            
            CGRect planeRect = [layoutManager boundingRectForGlyphRange:dogBusLead
                                                      inTextContainer:textContainer];
            
            
            CGRect binBreakWetRect = CGRectOffset(planeRect, spanSuccessPushTibetanLappish.x, spanSuccessPushTibetanLappish.y);
            
            
            if (CGRectContainsPoint(binBreakWetRect, darkPinIron)) {
                spaDefaultPub = YES;
                *stop = YES;
            }
        }
    }];
    
    if (spaDefaultPub) {
        
        
        [self reloadDescribesTenTallTopArbiterLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:twitterTildePredictedSentYearWon
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *nineText = label.attributedText.string;
    NSRange floorAccording = [nineText rangeOfString:CityPublish.throughHosting.waxEndEarMight];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, floorAccording)) {
        
        
        if (self.promptShapeMemberBagLoadSiblings) {
            self.promptShapeMemberBagLoadSiblings();
        }
    }
}


- (void)reloadDescribesTenTallTopArbiterLabel:(OldestAssetLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL penOldSoft = 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 gaelicCar = !_saltCurvePress;
        
        
        NSTextAttachment *attachedShift = [[NSTextAttachment alloc] init];
        
        
        UIColor *optionColor = gaelicCar ? [CityPublish audioRestColor]: UIColor.lightGrayColor;
        UIImage *setupCupImage = [UIImage extentsTenGroupDistortedTriggerName:gaelicCar ? CityPublish.halfInferCan.queryLooseVariableThreeDroppedTension :CityPublish.halfInferCan.intervalDarkenSubscriptTurkmenResponderSource];
        
        
        attachedShift.image = [[setupCupImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:optionColor];
        attachedShift.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:attachedShift range:range];
        
        _saltCurvePress = gaelicCar;
        penOldSoft = YES;
        *stop = YES;
    }];
    
    if (penOldSoft) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
