






#import "MinProtocolLabel.h"
#import "CutEightLow.h"
#import "UIImage+EraImage.h"

@implementation MinProtocolLabel

+ (MinProtocolLabel *)mustInferiorsLabel {
    return [self mustInferiorsLabel:YES];
}

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

    NSAttributedString *descenderQualifierBridgeSockGregorian = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage logicalPrintTradPrepExtentsName:CutEightLow.licenseSmart.kitEqualNotResumeSindhiHost] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        descenderQualifierBridgeSockGregorian = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = CutEightLow.mailRetDropSee.betterColumn;
    NSMutableAttributedString *idleLeaveWhile = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange sayPipeThinBig = [text rangeOfString:CutEightLow.mailRetDropSee.needPubKeepCat];
    if (sayPipeThinBig.location != NSNotFound) {
        [idleLeaveWhile addAttribute:NSForegroundColorAttributeName value:[CutEightLow megabytesColor] range:sayPipeThinBig];
        [idleLeaveWhile addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:sayPipeThinBig];
    }

    
    NSMutableAttributedString *cardReportsWeekendFactoryDays = [[NSMutableAttributedString alloc] init];
    if (descenderQualifierBridgeSockGregorian) {
        [cardReportsWeekendFactoryDays appendAttributedString:descenderQualifierBridgeSockGregorian];
    }
    [cardReportsWeekendFactoryDays appendAttributedString:idleLeaveWhile];
    
    label.attributedText = cardReportsWeekendFactoryDays;
    
    
    UITapGestureRecognizer *brandScale = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(hundredsServicesDigitalSectionCapable:)];
    [label addGestureRecognizer:brandScale];
    
    return label;
}

- (void)setScaleBendWhite:(BOOL)scaleBendWhite {
    _scaleBendWhite = !scaleBendWhite;
    [self gigabytesRespondsResponderButtonDivideSpellLabel:self];
}

- (void)hundredsServicesDigitalSectionCapable:(UITapGestureRecognizer *)brandScale {
    MinProtocolLabel *label = (MinProtocolLabel *)brandScale.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 diskMixLock = [brandScale locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint islamicReplacedCheckArmpitDirectory = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint globalShoulderSlovakAbovePreventsBar = CGPointMake(
        diskMixLock.x - islamicReplacedCheckArmpitDirectory.x,
        diskMixLock.y - islamicReplacedCheckArmpitDirectory.y
    );
    
    
    __block BOOL pagerRankText = 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 barRunPair;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&barRunPair];
            
            
            CGRect gradeRect = [layoutManager boundingRectForGlyphRange:barRunPair
                                                      inTextContainer:textContainer];
            
            
            CGRect coalesceTipRect = CGRectOffset(gradeRect, islamicReplacedCheckArmpitDirectory.x, islamicReplacedCheckArmpitDirectory.y);
            
            
            if (CGRectContainsPoint(coalesceTipRect, diskMixLock)) {
                pagerRankText = YES;
                *stop = YES;
            }
        }
    }];
    
    if (pagerRankText) {
        
        
        [self gigabytesRespondsResponderButtonDivideSpellLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:globalShoulderSlovakAbovePreventsBar
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *pageText = label.attributedText.string;
    NSRange sayPipeThinBig = [pageText rangeOfString:CutEightLow.mailRetDropSee.needPubKeepCat];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, sayPipeThinBig)) {
        
        
        if (self.askLinearPromotionMuteLeadHue) {
            self.askLinearPromotionMuteLeadHue();
        }
    }
}


- (void)gigabytesRespondsResponderButtonDivideSpellLabel:(MinProtocolLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL supportAny = 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 withinSin = !_scaleBendWhite;
        
        
        NSTextAttachment *mayTooRenewed = [[NSTextAttachment alloc] init];
        
        
        UIColor *attachColor = withinSin ? [CutEightLow megabytesColor]: UIColor.lightGrayColor;
        UIImage *panelOutImage = [UIImage logicalPrintTradPrepExtentsName:withinSin ? CutEightLow.licenseSmart.pinLocationsUplinkRationalBadmintonAllocator :CutEightLow.licenseSmart.kitEqualNotResumeSindhiHost];
        
        
        mayTooRenewed.image = [[panelOutImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:attachColor];
        mayTooRenewed.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:mayTooRenewed range:range];
        
        _scaleBendWhite = withinSin;
        supportAny = YES;
        *stop = YES;
    }];
    
    if (supportAny) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
