






#import "PlateTapRawLabel.h"
#import "IndicesBest.h"
#import "UIImage+SumImage.h"

@implementation PlateTapRawLabel

+ (PlateTapRawLabel *)maskForLawFixLabel {
    return [self maskForLawFixLabel:YES];
}

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

    NSAttributedString *cropOwnEggTheRepeats = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage busFactoredSockFlemishDeliveryName:IndicesBest.trustMainArm.fragmentsCollectorFaxHowBankersHis] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        cropOwnEggTheRepeats = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = IndicesBest.linerSharpness.wayDirection;
    NSMutableAttributedString *retStakeKinFax = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange bodySeeDryHand = [text rangeOfString:IndicesBest.linerSharpness.penZipLargeFat];
    if (bodySeeDryHand.location != NSNotFound) {
        [retStakeKinFax addAttribute:NSForegroundColorAttributeName value:[IndicesBest sexExtrasColor] range:bodySeeDryHand];
        [retStakeKinFax addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:bodySeeDryHand];
    }

    
    NSMutableAttributedString *smallestForwardsAuditDiphthongMode = [[NSMutableAttributedString alloc] init];
    if (cropOwnEggTheRepeats) {
        [smallestForwardsAuditDiphthongMode appendAttributedString:cropOwnEggTheRepeats];
    }
    [smallestForwardsAuditDiphthongMode appendAttributedString:retStakeKinFax];
    
    label.attributedText = smallestForwardsAuditDiphthongMode;
    
    
    UITapGestureRecognizer *addPlanFar = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(authorsInvertMinDrainPost:)];
    [label addGestureRecognizer:addPlanFar];
    
    return label;
}

- (void)setPolishRevision:(BOOL)polishRevision {
    _polishRevision = !polishRevision;
    [self exchangesShowersReadoutIntervalsNowOddLabel:self];
}

- (void)authorsInvertMinDrainPost:(UITapGestureRecognizer *)addPlanFar {
    PlateTapRawLabel *label = (PlateTapRawLabel *)addPlanFar.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 bayerJobFix = [addPlanFar locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint tabLimitAlphabetStrokedIdentify = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint publicTrademarkStarGlucoseJobNine = CGPointMake(
        bayerJobFix.x - tabLimitAlphabetStrokedIdentify.x,
        bayerJobFix.y - tabLimitAlphabetStrokedIdentify.y
    );
    
    
    __block BOOL ownerSobStone = 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 grayInside;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&grayInside];
            
            
            CGRect bloodRect = [layoutManager boundingRectForGlyphRange:grayInside
                                                      inTextContainer:textContainer];
            
            
            CGRect hyphenHindiRect = CGRectOffset(bloodRect, tabLimitAlphabetStrokedIdentify.x, tabLimitAlphabetStrokedIdentify.y);
            
            
            if (CGRectContainsPoint(hyphenHindiRect, bayerJobFix)) {
                ownerSobStone = YES;
                *stop = YES;
            }
        }
    }];
    
    if (ownerSobStone) {
        
        
        [self exchangesShowersReadoutIntervalsNowOddLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:publicTrademarkStarGlucoseJobNine
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *lessText = label.attributedText.string;
    NSRange bodySeeDryHand = [lessText rangeOfString:IndicesBest.linerSharpness.penZipLargeFat];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, bodySeeDryHand)) {
        
        
        if (self.idiomGuestDirtyLinerFaceRate) {
            self.idiomGuestDirtyLinerFaceRate();
        }
    }
}


- (void)exchangesShowersReadoutIntervalsNowOddLabel:(PlateTapRawLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL mapLocales = 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 nineBound = !_polishRevision;
        
        
        NSTextAttachment *hairParagraph = [[NSTextAttachment alloc] init];
        
        
        UIColor *asleepColor = nineBound ? [IndicesBest sexExtrasColor]: UIColor.lightGrayColor;
        UIImage *equalSonImage = [UIImage busFactoredSockFlemishDeliveryName:nineBound ? IndicesBest.trustMainArm.alignedEditorPrinterCertNotifiedCap :IndicesBest.trustMainArm.fragmentsCollectorFaxHowBankersHis];
        
        
        hairParagraph.image = [[equalSonImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:asleepColor];
        hairParagraph.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:hairParagraph range:range];
        
        _polishRevision = nineBound;
        mapLocales = YES;
        *stop = YES;
    }];
    
    if (mapLocales) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
