






#import "IncreaseBedLabel.h"
#import "RaceRateYou.h"
#import "UIImage+TagImage.h"

@implementation IncreaseBedLabel

+ (IncreaseBedLabel *)capWetReachedLabel {
    return [self capWetReachedLabel:YES];
}

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

    NSAttributedString *callingDidRearDiamondLeftover = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage dependingLigatureDimensionBuildEdgaName:RaceRateYou.wristBoldNot.negateGurationUniversalVerticalOpacityDivide] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        callingDidRearDiamondLeftover = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = RaceRateYou.maxSnapYearShe.kinHowAuthor;
    NSMutableAttributedString *unsavedInverse = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange mayTildeAddSee = [text rangeOfString:RaceRateYou.maxSnapYearShe.boxAskFlowClip];
    if (mayTildeAddSee.location != NSNotFound) {
        [unsavedInverse addAttribute:NSForegroundColorAttributeName value:[RaceRateYou ropeCauseColor] range:mayTildeAddSee];
        [unsavedInverse addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:mayTildeAddSee];
    }

    
    NSMutableAttributedString *hueQueryingReliableFractionRemove = [[NSMutableAttributedString alloc] init];
    if (callingDidRearDiamondLeftover) {
        [hueQueryingReliableFractionRemove appendAttributedString:callingDidRearDiamondLeftover];
    }
    [hueQueryingReliableFractionRemove appendAttributedString:unsavedInverse];
    
    label.attributedText = hueQueryingReliableFractionRemove;
    
    
    UITapGestureRecognizer *thinCorner = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(exchangesTooCancelInitiatedTorque:)];
    [label addGestureRecognizer:thinCorner];
    
    return label;
}

- (void)setNorthDashSolid:(BOOL)northDashSolid {
    _northDashSolid = !northDashSolid;
    [self helpNetCommentRecordAscentAddressLabel:self];
}

- (void)exchangesTooCancelInitiatedTorque:(UITapGestureRecognizer *)thinCorner {
    IncreaseBedLabel *label = (IncreaseBedLabel *)thinCorner.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 suddenForce = [thinCorner locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint stepperIssueDarkEpisodeDigit = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint offSeparatePortalUighurLoopAction = CGPointMake(
        suddenForce.x - stepperIssueDarkEpisodeDigit.x,
        suddenForce.y - stepperIssueDarkEpisodeDigit.y
    );
    
    
    __block BOOL postLeapIssue = 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 putRopeFar;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&putRopeFar];
            
            
            CGRect spellRect = [layoutManager boundingRectForGlyphRange:putRopeFar
                                                      inTextContainer:textContainer];
            
            
            CGRect powerFarNetRect = CGRectOffset(spellRect, stepperIssueDarkEpisodeDigit.x, stepperIssueDarkEpisodeDigit.y);
            
            
            if (CGRectContainsPoint(powerFarNetRect, suddenForce)) {
                postLeapIssue = YES;
                *stop = YES;
            }
        }
    }];
    
    if (postLeapIssue) {
        
        
        [self helpNetCommentRecordAscentAddressLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:offSeparatePortalUighurLoopAction
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *darkText = label.attributedText.string;
    NSRange mayTildeAddSee = [darkText rangeOfString:RaceRateYou.maxSnapYearShe.boxAskFlowClip];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, mayTildeAddSee)) {
        
        
        if (self.justClipCharacterMindToneHer) {
            self.justClipCharacterMindToneHer();
        }
    }
}


- (void)helpNetCommentRecordAscentAddressLabel:(IncreaseBedLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL bankCreamy = 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 millBasic = !_northDashSolid;
        
        
        NSTextAttachment *wordWonPutHer = [[NSTextAttachment alloc] init];
        
        
        UIColor *panOffColor = millBasic ? [RaceRateYou ropeCauseColor]: UIColor.lightGrayColor;
        UIImage *rankTaskImage = [UIImage dependingLigatureDimensionBuildEdgaName:millBasic ? RaceRateYou.wristBoldNot.supportedNaturalNineStepOwnConstants :RaceRateYou.wristBoldNot.negateGurationUniversalVerticalOpacityDivide];
        
        
        wordWonPutHer.image = [[rankTaskImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:panOffColor];
        wordWonPutHer.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:wordWonPutHer range:range];
        
        _northDashSolid = millBasic;
        bankCreamy = YES;
        *stop = YES;
    }];
    
    if (bankCreamy) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
