






#import "TipQuickDayLabel.h"
#import "RuleListCut.h"
#import "UIImage+HasImage.h"

@implementation TipQuickDayLabel

+ (TipQuickDayLabel *)rowFunSobDarkLabel {
    return [self rowFunSobDarkLabel:YES];
}

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

    NSAttributedString *versionsSideDiscardedPanoramasKey = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage infoBusFilterVariationTurnName:RuleListCut.coloredDraft.andSafetyRedoneWatchIndicatedPair] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        versionsSideDiscardedPanoramasKey = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = RuleListCut.costSonKnowKit.askSeekSplat;
    NSMutableAttributedString *exactPrimaries = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange mostDateSelect = [text rangeOfString:RuleListCut.costSonKnowKit.mixMileZipBeen];
    if (mostDateSelect.location != NSNotFound) {
        [exactPrimaries addAttribute:NSForegroundColorAttributeName value:[RuleListCut slopeLockColor] range:mostDateSelect];
        [exactPrimaries addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:mostDateSelect];
    }

    
    NSMutableAttributedString *kitSymptomAttachTrailingRear = [[NSMutableAttributedString alloc] init];
    if (versionsSideDiscardedPanoramasKey) {
        [kitSymptomAttachTrailingRear appendAttributedString:versionsSideDiscardedPanoramasKey];
    }
    [kitSymptomAttachTrailingRear appendAttributedString:exactPrimaries];
    
    label.attributedText = kitSymptomAttachTrailingRear;
    
    
    UITapGestureRecognizer *twoSubFact = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(respondsUnsavedAndDigestSin:)];
    [label addGestureRecognizer:twoSubFact];
    
    return label;
}

- (void)setWetDarkSexFlat:(BOOL)wetDarkSexFlat {
    _wetDarkSexFlat = !wetDarkSexFlat;
    [self browsingFifteenAwakeAnimateSlidingClientsLabel:self];
}

- (void)respondsUnsavedAndDigestSin:(UITapGestureRecognizer *)twoSubFact {
    TipQuickDayLabel *label = (TipQuickDayLabel *)twoSubFact.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 recyclePast = [twoSubFact locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint regionTicketsFlushedSubscriptMan = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint unifySkinAdapterKeysCommentPin = CGPointMake(
        recyclePast.x - regionTicketsFlushedSubscriptMan.x,
        recyclePast.y - regionTicketsFlushedSubscriptMan.y
    );
    
    
    __block BOOL oneGarbageWax = 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 askPenFlag;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&askPenFlag];
            
            
            CGRect awakeRect = [layoutManager boundingRectForGlyphRange:askPenFlag
                                                      inTextContainer:textContainer];
            
            
            CGRect rawWaistPubRect = CGRectOffset(awakeRect, regionTicketsFlushedSubscriptMan.x, regionTicketsFlushedSubscriptMan.y);
            
            
            if (CGRectContainsPoint(rawWaistPubRect, recyclePast)) {
                oneGarbageWax = YES;
                *stop = YES;
            }
        }
    }];
    
    if (oneGarbageWax) {
        
        
        [self browsingFifteenAwakeAnimateSlidingClientsLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:unifySkinAdapterKeysCommentPin
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *knowText = label.attributedText.string;
    NSRange mostDateSelect = [knowText rangeOfString:RuleListCut.costSonKnowKit.mixMileZipBeen];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, mostDateSelect)) {
        
        
        if (self.undoneQuotesBrokenOurNotifyGallons) {
            self.undoneQuotesBrokenOurNotifyGallons();
        }
    }
}


- (void)browsingFifteenAwakeAnimateSlidingClientsLabel:(TipQuickDayLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL tallUpside = 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 longerBus = !_wetDarkSexFlat;
        
        
        NSTextAttachment *pubLabelClose = [[NSTextAttachment alloc] init];
        
        
        UIColor *forForColor = longerBus ? [RuleListCut slopeLockColor]: UIColor.lightGrayColor;
        UIImage *renamingImage = [UIImage infoBusFilterVariationTurnName:longerBus ? RuleListCut.coloredDraft.alienTooBackupBackwardsNowPrefix :RuleListCut.coloredDraft.andSafetyRedoneWatchIndicatedPair];
        
        
        pubLabelClose.image = [[renamingImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:forForColor];
        pubLabelClose.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:pubLabelClose range:range];
        
        _wetDarkSexFlat = longerBus;
        tallUpside = YES;
        *stop = YES;
    }];
    
    if (tallUpside) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
