






#import "CallBurmeseLabel.h"
#import "PaceDownHue.h"
#import "UIImage+KeyImage.h"

@implementation CallBurmeseLabel

+ (CallBurmeseLabel *)sliderSwedishLabel {
    return [self sliderSwedishLabel:YES];
}

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

    NSAttributedString *linearlyLockingContactScatteredPascal = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage whoGallonsFemaleReportingSawName:PaceDownHue.absoluteAuto.herCursorsHallUsedAssistiveWritten] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        linearlyLockingContactScatteredPascal = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = PaceDownHue.touchBusyMalay.sumAirIssuer;
    NSMutableAttributedString *bezelConverged = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange frontHomeClick = [text rangeOfString:PaceDownHue.touchBusyMalay.yetSplatSobLog];
    if (frontHomeClick.location != NSNotFound) {
        [bezelConverged addAttribute:NSForegroundColorAttributeName value:[PaceDownHue frequencyColor] range:frontHomeClick];
        [bezelConverged addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:frontHomeClick];
    }

    
    NSMutableAttributedString *reduceBondIssueProceedGeometry = [[NSMutableAttributedString alloc] init];
    if (linearlyLockingContactScatteredPascal) {
        [reduceBondIssueProceedGeometry appendAttributedString:linearlyLockingContactScatteredPascal];
    }
    [reduceBondIssueProceedGeometry appendAttributedString:bezelConverged];
    
    label.attributedText = reduceBondIssueProceedGeometry;
    
    
    UITapGestureRecognizer *handleLoss = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(tabDebuggerPairWorkoutsTry:)];
    [label addGestureRecognizer:handleLoss];
    
    return label;
}

- (void)setShadowBypassed:(BOOL)shadowBypassed {
    _shadowBypassed = !shadowBypassed;
    [self instantAggregateTabParameterShakeSonLabel:self];
}

- (void)tabDebuggerPairWorkoutsTry:(UITapGestureRecognizer *)handleLoss {
    CallBurmeseLabel *label = (CallBurmeseLabel *)handleLoss.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 simpleLabel = [handleLoss locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint archivedRequestedDiscountAudibleDecrypt = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint specifySayEventFinalizeKazakhSpecified = CGPointMake(
        simpleLabel.x - archivedRequestedDiscountAudibleDecrypt.x,
        simpleLabel.y - archivedRequestedDiscountAudibleDecrypt.y
    );
    
    
    __block BOOL manHerRedPass = 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 dayStopSun;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&dayStopSun];
            
            
            CGRect phoneRect = [layoutManager boundingRectForGlyphRange:dayStopSun
                                                      inTextContainer:textContainer];
            
            
            CGRect workPeerSumRect = CGRectOffset(phoneRect, archivedRequestedDiscountAudibleDecrypt.x, archivedRequestedDiscountAudibleDecrypt.y);
            
            
            if (CGRectContainsPoint(workPeerSumRect, simpleLabel)) {
                manHerRedPass = YES;
                *stop = YES;
            }
        }
    }];
    
    if (manHerRedPass) {
        
        
        [self instantAggregateTabParameterShakeSonLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:specifySayEventFinalizeKazakhSpecified
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *zoneText = label.attributedText.string;
    NSRange frontHomeClick = [zoneText rangeOfString:PaceDownHue.touchBusyMalay.yetSplatSobLog];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, frontHomeClick)) {
        
        
        if (self.stiffnessTamilAdjustedAllowableSendCloud) {
            self.stiffnessTamilAdjustedAllowableSendCloud();
        }
    }
}


- (void)instantAggregateTabParameterShakeSonLabel:(CallBurmeseLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL butFatFilm = 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 photosCat = !_shadowBypassed;
        
        
        NSTextAttachment *installsShape = [[NSTextAttachment alloc] init];
        
        
        UIColor *widgetColor = photosCat ? [PaceDownHue frequencyColor]: UIColor.lightGrayColor;
        UIImage *sayHelloImage = [UIImage whoGallonsFemaleReportingSawName:photosCat ? PaceDownHue.absoluteAuto.centersLocalityLocalesDisappearAmharicRational :PaceDownHue.absoluteAuto.herCursorsHallUsedAssistiveWritten];
        
        
        installsShape.image = [[sayHelloImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:widgetColor];
        installsShape.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:installsShape range:range];
        
        _shadowBypassed = photosCat;
        butFatFilm = YES;
        *stop = YES;
    }];
    
    if (butFatFilm) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
