






#import "SoloistDateLabel.h"
#import "ReloadThird.h"
#import "UIImage+HasImage.h"

@implementation SoloistDateLabel

+ (SoloistDateLabel *)focalRetFiberLabel {
    return [self focalRetFiberLabel:YES];
}

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

    NSAttributedString *packetsAudiogramWhoLocaleObstacle = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage removeFadeMaxEngravedDivideName:ReloadThird.overlapQuote.mediumHeapGracefulGuaraniForbidCircular] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        packetsAudiogramWhoLocaleObstacle = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = ReloadThird.phoneKitTenTen.sobVisionZip;
    NSMutableAttributedString *trapHallPhotos = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange frontContained = [text rangeOfString:ReloadThird.phoneKitTenTen.burstEastBring];
    if (frontContained.location != NSNotFound) {
        [trapHallPhotos addAttribute:NSForegroundColorAttributeName value:[ReloadThird fairBlockColor] range:frontContained];
        [trapHallPhotos addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:frontContained];
    }

    
    NSMutableAttributedString *saltSignalingBetterAllocatorSample = [[NSMutableAttributedString alloc] init];
    if (packetsAudiogramWhoLocaleObstacle) {
        [saltSignalingBetterAllocatorSample appendAttributedString:packetsAudiogramWhoLocaleObstacle];
    }
    [saltSignalingBetterAllocatorSample appendAttributedString:trapHallPhotos];
    
    label.attributedText = saltSignalingBetterAllocatorSample;
    
    
    UITapGestureRecognizer *penBattery = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(bedSliderRevisionUsabilityMegabytes:)];
    [label addGestureRecognizer:penBattery];
    
    return label;
}

- (void)setLoudInfoSixNot:(BOOL)loudInfoSixNot {
    _loudInfoSixNot = !loudInfoSixNot;
    [self segmentSoundAlertWinDescendedCaseLabel:self];
}

- (void)bedSliderRevisionUsabilityMegabytes:(UITapGestureRecognizer *)penBattery {
    SoloistDateLabel *label = (SoloistDateLabel *)penBattery.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 mapCampaign = [penBattery locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint clearedEmptyWeightWaistTwo = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint kitVerifyBypassBarrierOverallUnlikely = CGPointMake(
        mapCampaign.x - clearedEmptyWeightWaistTwo.x,
        mapCampaign.y - clearedEmptyWeightWaistTwo.y
    );
    
    
    __block BOOL verticalBuddy = 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 iodineEcho;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&iodineEcho];
            
            
            CGRect touchRect = [layoutManager boundingRectForGlyphRange:iodineEcho
                                                      inTextContainer:textContainer];
            
            
            CGRect mixBeenTreeRect = CGRectOffset(touchRect, clearedEmptyWeightWaistTwo.x, clearedEmptyWeightWaistTwo.y);
            
            
            if (CGRectContainsPoint(mixBeenTreeRect, mapCampaign)) {
                verticalBuddy = YES;
                *stop = YES;
            }
        }
    }];
    
    if (verticalBuddy) {
        
        
        [self segmentSoundAlertWinDescendedCaseLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:kitVerifyBypassBarrierOverallUnlikely
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *yearText = label.attributedText.string;
    NSRange frontContained = [yearText rangeOfString:ReloadThird.phoneKitTenTen.burstEastBring];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, frontContained)) {
        
        
        if (self.touchesAttempterQuechuaDetailedLargestVolatile) {
            self.touchesAttempterQuechuaDetailedLargestVolatile();
        }
    }
}


- (void)segmentSoundAlertWinDescendedCaseLabel:(SoloistDateLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL clockStart = 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 roleEmail = !_loudInfoSixNot;
        
        
        NSTextAttachment *whileLiftCase = [[NSTextAttachment alloc] init];
        
        
        UIColor *panSayColor = roleEmail ? [ReloadThird fairBlockColor]: UIColor.lightGrayColor;
        UIImage *heartTenImage = [UIImage removeFadeMaxEngravedDivideName:roleEmail ? ReloadThird.overlapQuote.externStrokeChangingBehaviorStoreAssert :ReloadThird.overlapQuote.mediumHeapGracefulGuaraniForbidCircular];
        
        
        whileLiftCase.image = [[heartTenImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:panSayColor];
        whileLiftCase.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:whileLiftCase range:range];
        
        _loudInfoSixNot = roleEmail;
        clockStart = YES;
        *stop = YES;
    }];
    
    if (clockStart) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
