






#import "TwoSeeTitleLabel.h"
#import "EventPinWho.h"
#import "UIImage+SpaImage.h"

@implementation TwoSeeTitleLabel

+ (TwoSeeTitleLabel *)nowRadiansNotLabel {
    return [self nowRadiansNotLabel:YES];
}

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

    NSAttributedString *callFlatnessExposureDaysLocalized = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage zipRecoveryAcuteTowerWayName:EventPinWho.animatingYet.lenientMoodPanoramaBinDenyLibrary] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        callFlatnessExposureDaysLocalized = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = EventPinWho.prologCollapse.sonRingMalay;
    NSMutableAttributedString *youSkinFlipHit = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange japaneseRepair = [text rangeOfString:EventPinWho.prologCollapse.enterPingStake];
    if (japaneseRepair.location != NSNotFound) {
        [youSkinFlipHit addAttribute:NSForegroundColorAttributeName value:[EventPinWho semaphoreColor] range:japaneseRepair];
        [youSkinFlipHit addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:japaneseRepair];
    }

    
    NSMutableAttributedString *shelfListenerStoodOutGarbage = [[NSMutableAttributedString alloc] init];
    if (callFlatnessExposureDaysLocalized) {
        [shelfListenerStoodOutGarbage appendAttributedString:callFlatnessExposureDaysLocalized];
    }
    [shelfListenerStoodOutGarbage appendAttributedString:youSkinFlipHit];
    
    label.attributedText = shelfListenerStoodOutGarbage;
    
    
    UITapGestureRecognizer *capRussian = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(modernChlorideLicenseArtistIcy:)];
    [label addGestureRecognizer:capRussian];
    
    return label;
}

- (void)setStartingDuplex:(BOOL)startingDuplex {
    _startingDuplex = !startingDuplex;
    [self flatnessZoneClipEffectiveEngineerAnyLabel:self];
}

- (void)modernChlorideLicenseArtistIcy:(UITapGestureRecognizer *)capRussian {
    TwoSeeTitleLabel *label = (TwoSeeTitleLabel *)capRussian.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 unsavedLost = [capRussian locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint startupOddSwitchForkCustom = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint wideAudiogramOurRadioDisabledPossible = CGPointMake(
        unsavedLost.x - startupOddSwitchForkCustom.x,
        unsavedLost.y - startupOddSwitchForkCustom.y
    );
    
    
    __block BOOL heavyProxySex = 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 notMenSink;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&notMenSink];
            
            
            CGRect enterRect = [layoutManager boundingRectForGlyphRange:notMenSink
                                                      inTextContainer:textContainer];
            
            
            CGRect terminalWinRect = CGRectOffset(enterRect, startupOddSwitchForkCustom.x, startupOddSwitchForkCustom.y);
            
            
            if (CGRectContainsPoint(terminalWinRect, unsavedLost)) {
                heavyProxySex = YES;
                *stop = YES;
            }
        }
    }];
    
    if (heavyProxySex) {
        
        
        [self flatnessZoneClipEffectiveEngineerAnyLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:wideAudiogramOurRadioDisabledPossible
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *faceText = label.attributedText.string;
    NSRange japaneseRepair = [faceText rangeOfString:EventPinWho.prologCollapse.enterPingStake];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, japaneseRepair)) {
        
        
        if (self.butPortKinLossHelpHandover) {
            self.butPortKinLossHelpHandover();
        }
    }
}


- (void)flatnessZoneClipEffectiveEngineerAnyLabel:(TwoSeeTitleLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL busEndsMap = 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 potassium = !_startingDuplex;
        
        
        NSTextAttachment *oddEraRestore = [[NSTextAttachment alloc] init];
        
        
        UIColor *sixPubColor = potassium ? [EventPinWho semaphoreColor]: UIColor.lightGrayColor;
        UIImage *pointTwoImage = [UIImage zipRecoveryAcuteTowerWayName:potassium ? EventPinWho.animatingYet.soundRepeatRecipientPongControlProxy :EventPinWho.animatingYet.lenientMoodPanoramaBinDenyLibrary];
        
        
        oddEraRestore.image = [[pointTwoImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:sixPubColor];
        oddEraRestore.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:oddEraRestore range:range];
        
        _startingDuplex = potassium;
        busEndsMap = YES;
        *stop = YES;
    }];
    
    if (busEndsMap) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
