






#import "BottomLegalLabel.h"
#import "HourEllipse.h"
#import "UIImage+SawImage.h"

@implementation BottomLegalLabel

+ (BottomLegalLabel *)awakeTamilHerLabel {
    return [self awakeTamilHerLabel:YES];
}

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

    NSAttributedString *quantityConflictsStableShrinkSigma = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage loveClinicalCornerDecryptedAsteriskName:HourEllipse.howSignaling.matchConjugateDetailBothWinSigma] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        quantityConflictsStableShrinkSigma = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = HourEllipse.alienSemaphore.bayerTrainer;
    NSMutableAttributedString *bandMinuteRare = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange subtitleSafety = [text rangeOfString:HourEllipse.alienSemaphore.binDanceMixSpa];
    if (subtitleSafety.location != NSNotFound) {
        [bandMinuteRare addAttribute:NSForegroundColorAttributeName value:[HourEllipse screenKinColor] range:subtitleSafety];
        [bandMinuteRare addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:subtitleSafety];
    }

    
    NSMutableAttributedString *rotateFastestUnboundAggregatePrimaries = [[NSMutableAttributedString alloc] init];
    if (quantityConflictsStableShrinkSigma) {
        [rotateFastestUnboundAggregatePrimaries appendAttributedString:quantityConflictsStableShrinkSigma];
    }
    [rotateFastestUnboundAggregatePrimaries appendAttributedString:bandMinuteRare];
    
    label.attributedText = rotateFastestUnboundAggregatePrimaries;
    
    
    UITapGestureRecognizer *advisedKit = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(binModuleIllSortFeature:)];
    [label addGestureRecognizer:advisedKit];
    
    return label;
}

- (void)setMinimizeSource:(BOOL)minimizeSource {
    _minimizeSource = !minimizeSource;
    [self startingLockDietaryGracefulLeftOverflowLabel:self];
}

- (void)binModuleIllSortFeature:(UITapGestureRecognizer *)advisedKit {
    BottomLegalLabel *label = (BottomLegalLabel *)advisedKit.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 ownInfoKeep = [advisedKit locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint funHardRedoneZoomUnbound = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint digestCellphoneGrantingCubeBufferedFreezing = CGPointMake(
        ownInfoKeep.x - funHardRedoneZoomUnbound.x,
        ownInfoKeep.y - funHardRedoneZoomUnbound.y
    );
    
    
    __block BOOL muteWrongMake = 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 pintMinSum;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&pintMinSum];
            
            
            CGRect shortRect = [layoutManager boundingRectForGlyphRange:pintMinSum
                                                      inTextContainer:textContainer];
            
            
            CGRect unloadExistRect = CGRectOffset(shortRect, funHardRedoneZoomUnbound.x, funHardRedoneZoomUnbound.y);
            
            
            if (CGRectContainsPoint(unloadExistRect, ownInfoKeep)) {
                muteWrongMake = YES;
                *stop = YES;
            }
        }
    }];
    
    if (muteWrongMake) {
        
        
        [self startingLockDietaryGracefulLeftOverflowLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:digestCellphoneGrantingCubeBufferedFreezing
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *saveText = label.attributedText.string;
    NSRange subtitleSafety = [saveText rangeOfString:HourEllipse.alienSemaphore.binDanceMixSpa];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, subtitleSafety)) {
        
        
        if (self.trimmingWithRealmComponentDecigramsSoft) {
            self.trimmingWithRealmComponentDecigramsSoft();
        }
    }
}


- (void)startingLockDietaryGracefulLeftOverflowLabel:(BottomLegalLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL alpineFail = 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 lastLeast = !_minimizeSource;
        
        
        NSTextAttachment *spaSinMeanHas = [[NSTextAttachment alloc] init];
        
        
        UIColor *bigAreColor = lastLeast ? [HourEllipse screenKinColor]: UIColor.lightGrayColor;
        UIImage *fastCellImage = [UIImage loveClinicalCornerDecryptedAsteriskName:lastLeast ? HourEllipse.howSignaling.siteEphemeralElapsedPostalThousandTip :HourEllipse.howSignaling.matchConjugateDetailBothWinSigma];
        
        
        spaSinMeanHas.image = [[fastCellImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:bigAreColor];
        spaSinMeanHas.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:spaSinMeanHas range:range];
        
        _minimizeSource = lastLeast;
        alpineFail = YES;
        *stop = YES;
    }];
    
    if (alpineFail) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
