






#import "DryPairKnowLabel.h"
#import "InvertPinch.h"
#import "UIImage+WayImage.h"

@implementation DryPairKnowLabel

+ (DryPairKnowLabel *)storeSpaExitsLabel {
    return [self storeSpaExitsLabel:YES];
}

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

    NSAttributedString *covariantResizingFreestyleItsDiscover = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage redirectsDeveloperTemporalSameMotionName:InvertPinch.didThousands.pauseEmergencyFamilyUnsignedPreviousSlope] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        covariantResizingFreestyleItsDiscover = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = InvertPinch.knowSunTalkHas.chromaticCan;
    NSMutableAttributedString *procedureDepth = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange sinJustHailHue = [text rangeOfString:InvertPinch.knowSunTalkHas.seeSinBinTrash];
    if (sinJustHailHue.location != NSNotFound) {
        [procedureDepth addAttribute:NSForegroundColorAttributeName value:[InvertPinch indicatedColor] range:sinJustHailHue];
        [procedureDepth addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:sinJustHailHue];
    }

    
    NSMutableAttributedString *topGaelicCountingHerStay = [[NSMutableAttributedString alloc] init];
    if (covariantResizingFreestyleItsDiscover) {
        [topGaelicCountingHerStay appendAttributedString:covariantResizingFreestyleItsDiscover];
    }
    [topGaelicCountingHerStay appendAttributedString:procedureDepth];
    
    label.attributedText = topGaelicCountingHerStay;
    
    
    UITapGestureRecognizer *growRawWas = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(callbackDaysStructurePunjabiPersist:)];
    [label addGestureRecognizer:growRawWas];
    
    return label;
}

- (void)setTwoPanStoneTap:(BOOL)twoPanStoneTap {
    _twoPanStoneTap = !twoPanStoneTap;
    [self softwareBasqueJumpGenericsPostcardFetchLabel:self];
}

- (void)callbackDaysStructurePunjabiPersist:(UITapGestureRecognizer *)growRawWas {
    DryPairKnowLabel *label = (DryPairKnowLabel *)growRawWas.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 whoIllAdobe = [growRawWas locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint notifyWasNaturalSumAnchor = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint funkDeletionPoolNotifyingBeginOld = CGPointMake(
        whoIllAdobe.x - notifyWasNaturalSumAnchor.x,
        whoIllAdobe.y - notifyWasNaturalSumAnchor.y
    );
    
    
    __block BOOL placeLocality = 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 slantLabel;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&slantLabel];
            
            
            CGRect fatalRect = [layoutManager boundingRectForGlyphRange:slantLabel
                                                      inTextContainer:textContainer];
            
            
            CGRect fallbackPopRect = CGRectOffset(fatalRect, notifyWasNaturalSumAnchor.x, notifyWasNaturalSumAnchor.y);
            
            
            if (CGRectContainsPoint(fallbackPopRect, whoIllAdobe)) {
                placeLocality = YES;
                *stop = YES;
            }
        }
    }];
    
    if (placeLocality) {
        
        
        [self softwareBasqueJumpGenericsPostcardFetchLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:funkDeletionPoolNotifyingBeginOld
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *hallText = label.attributedText.string;
    NSRange sinJustHailHue = [hallText rangeOfString:InvertPinch.knowSunTalkHas.seeSinBinTrash];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, sinJustHailHue)) {
        
        
        if (self.peakSeeAloneEncodeShowReal) {
            self.peakSeeAloneEncodeShowReal();
        }
    }
}


- (void)softwareBasqueJumpGenericsPostcardFetchLabel:(DryPairKnowLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL charEyeFat = 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 ironFlush = !_twoPanStoneTap;
        
        
        NSTextAttachment *feedAggregate = [[NSTextAttachment alloc] init];
        
        
        UIColor *looperColor = ironFlush ? [InvertPinch indicatedColor]: UIColor.lightGrayColor;
        UIImage *jumpKnowImage = [UIImage redirectsDeveloperTemporalSameMotionName:ironFlush ? InvertPinch.didThousands.milesConvertDuplexGreenCoercionProducer :InvertPinch.didThousands.pauseEmergencyFamilyUnsignedPreviousSlope];
        
        
        feedAggregate.image = [[jumpKnowImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:looperColor];
        feedAggregate.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:feedAggregate range:range];
        
        _twoPanStoneTap = ironFlush;
        charEyeFat = YES;
        *stop = YES;
    }];
    
    if (charEyeFat) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
