






#import "BinDaysPlusLabel.h"
#import "MenuCluster.h"
#import "UIImage+SonImage.h"

@implementation BinDaysPlusLabel

+ (BinDaysPlusLabel *)inuitDailySunLabel {
    return [self inuitDailySunLabel:YES];
}

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

    NSAttributedString *resourceOverflowAlignmentLacrosseHelper = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage rotateMicroHitNotifyingFutureName:MenuCluster.thirteenHand.menuFixLinearFifteenDefaultTamil] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        resourceOverflowAlignmentLacrosseHelper = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = MenuCluster.hallFloorExist.cutterCutSay;
    NSMutableAttributedString *oldBusAirStore = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange deleteControls = [text rangeOfString:MenuCluster.hallFloorExist.mostSayPinPace];
    if (deleteControls.location != NSNotFound) {
        [oldBusAirStore addAttribute:NSForegroundColorAttributeName value:[MenuCluster asleepYetColor] range:deleteControls];
        [oldBusAirStore addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:deleteControls];
    }

    
    NSMutableAttributedString *tibetanBeenSevenSpecifyFunk = [[NSMutableAttributedString alloc] init];
    if (resourceOverflowAlignmentLacrosseHelper) {
        [tibetanBeenSevenSpecifyFunk appendAttributedString:resourceOverflowAlignmentLacrosseHelper];
    }
    [tibetanBeenSevenSpecifyFunk appendAttributedString:oldBusAirStore];
    
    label.attributedText = tibetanBeenSevenSpecifyFunk;
    
    
    UITapGestureRecognizer *sexLookMix = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(permuteOddReferenceEncodeReply:)];
    [label addGestureRecognizer:sexLookMix];
    
    return label;
}

- (void)setMarkFixingLose:(BOOL)markFixingLose {
    _markFixingLose = !markFixingLose;
    [self artsCountInputCaseSubgroupStableLabel:self];
}

- (void)permuteOddReferenceEncodeReply:(UITapGestureRecognizer *)sexLookMix {
    BinDaysPlusLabel *label = (BinDaysPlusLabel *)sexLookMix.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 personalTen = [sexLookMix locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint toggleFunUpdateSayPerfusion = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint hitRespondLinerDispenseTipDance = CGPointMake(
        personalTen.x - toggleFunUpdateSayPerfusion.x,
        personalTen.y - toggleFunUpdateSayPerfusion.y
    );
    
    
    __block BOOL busShearVoice = 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 depthLiter;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&depthLiter];
            
            
            CGRect spellRect = [layoutManager boundingRectForGlyphRange:depthLiter
                                                      inTextContainer:textContainer];
            
            
            CGRect foodSwahiliRect = CGRectOffset(spellRect, toggleFunUpdateSayPerfusion.x, toggleFunUpdateSayPerfusion.y);
            
            
            if (CGRectContainsPoint(foodSwahiliRect, personalTen)) {
                busShearVoice = YES;
                *stop = YES;
            }
        }
    }];
    
    if (busShearVoice) {
        
        
        [self artsCountInputCaseSubgroupStableLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:hitRespondLinerDispenseTipDance
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *wakeText = label.attributedText.string;
    NSRange deleteControls = [wakeText rangeOfString:MenuCluster.hallFloorExist.mostSayPinPace];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, deleteControls)) {
        
        
        if (self.thickAltitudeJobWithinGetSplat) {
            self.thickAltitudeJobWithinGetSplat();
        }
    }
}


- (void)artsCountInputCaseSubgroupStableLabel:(BinDaysPlusLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL passFunWas = 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 clockBars = !_markFixingLose;
        
        
        NSTextAttachment *floorMeterAny = [[NSTextAttachment alloc] init];
        
        
        UIColor *posterColor = clockBars ? [MenuCluster asleepYetColor]: UIColor.lightGrayColor;
        UIImage *tagStateImage = [UIImage rotateMicroHitNotifyingFutureName:clockBars ? MenuCluster.thirteenHand.decreaseBinaryIcyRevealedOccurredSeparate :MenuCluster.thirteenHand.menuFixLinearFifteenDefaultTamil];
        
        
        floorMeterAny.image = [[tagStateImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:posterColor];
        floorMeterAny.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:floorMeterAny range:range];
        
        _markFixingLose = clockBars;
        passFunWas = YES;
        *stop = YES;
    }];
    
    if (passFunWas) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
