








#import "IndexesFeature.h"

#define CloseHalftone self.frame.size.width

@interface IndexesFeature()



@property (nonatomic, strong) NSMutableArray                            *ruleAgeArray;



@property (nonatomic, strong) NSMutableArray <StopSafetyMindCell *>      *plusArray;



@property (strong, nonatomic) NSMutableArray <StopSafetyMindCell *>      *illegalOuter;



@property (assign, nonatomic) NSInteger                                 count;



@property (nonatomic, assign) MiddleAsleepModeAlongsideRoot                          status;



@property (nonatomic, assign) NSInteger                                 channelCount;



@property (nonatomic, assign) CGFloat                                   runBit;

@end

@implementation IndexesFeature

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.status = AcquireCelsiusSubWarpLoopsRestored;
    }
    return self;
}

- (void)itsZipSpeech
{
    
    if (self.plusArray.firstObject) {
        
        
        StopSafetyMindCell *archeryView = self.plusArray.firstObject;
        
        archeryView.frame = CGRectMake(CloseHalftone, 0, archeryView.listHitSize.width, archeryView.listHitSize.height);
        
        self.runBit = archeryView.runBit;
        
        self.channelCount = archeryView.channelCount;
        
        
        NSInteger row = [self cupMegahertzDescribeMoireImproperDownService:archeryView];
        
        
        if (row >= 0) {
            
            
            [self.plusArray removeObjectAtIndex:0];
            
            
            if (![self.subviews containsObject:archeryView]) {
                [self addSubview:archeryView];
            }
            archeryView.frame = CGRectMake(CloseHalftone,  row * (archeryView.listHitSize.height + _runBit), archeryView.listHitSize.width, archeryView.listHitSize.height);
            
            
            [_ruleAgeArray setObject:archeryView atIndexedSubscript:row];
            
            
            if ([self.delegate respondsToSelector:@selector(limitExceedsView:willDisplayCell:)]) {
                [self.delegate limitExceedsView:self willDisplayCell:archeryView];
            }
            
            
            [self.illegalOuter addObject:archeryView];
            
            [archeryView bouncingEncodingLevelRenewLuminance:^{
                
                
                [archeryView setTransform:CGAffineTransformMakeTranslation(- archeryView.frame.size.width-CloseHalftone, 0)];
                
            } completion:^(BOOL finished) {
                
                [archeryView removeFromSuperview];
                
                
                [self.illegalOuter removeObject:archeryView];
                
                
                if ([self.delegate respondsToSelector:@selector(limitExceedsView:didEndDisplayingCell:)]) {
                    [self.delegate limitExceedsView:self didEndDisplayingCell:archeryView];
                }
                
                
                if (--self.count <= 0) {
                    if ([self.delegate respondsToSelector:@selector(ornamentHoldDetailedRevealPreciseSecureLoopsFat:)]) {
                        [self.delegate ornamentHoldDetailedRevealPreciseSecureLoopsFat:self];
                    }
                    self.count = 0;
                }
                
                

            }];
        }
    }
    
    [self performSelector:@selector(itsZipSpeech) withObject:nil afterDelay:0.45f];
}


- (void)eyeEndOffToken:(NSArray <StopSafetyMindCell *> *)barrages
{
    self.count += barrages.count;
    [self.plusArray addObjectsFromArray:barrages];
}

- (void)start
{
    if (self.status == WillStepsonAnchorsLoadingTowerEnd) {
        return;
    }
    self.status = WillStepsonAnchorsLoadingTowerEnd;
    
    [self itsZipSpeech];
}

- (void)stop
{
    if (self.status == AcquireCelsiusSubWarpLoopsRestored) {
        return;
    }
    self.status = AcquireCelsiusSubWarpLoopsRestored;
    
    if (self.illegalOuter.count) {
        [self.illegalOuter makeObjectsPerformSelector:@selector(pause)];
    }
    
    if (self.plusArray.count > 0) {
        [NSObject cancelPreviousPerformRequestsWithTarget:self];
    }
    
    
    [self.illegalOuter  makeObjectsPerformSelector:@selector(removeFromSuperview)];
    self.channelCount       = 0;
    self.count              = 0;
    [self.illegalOuter  removeAllObjects];
    [self.plusArray     removeAllObjects];
    [self.ruleAgeArray  removeAllObjects];
    
    self.illegalOuter       = nil;
    self.plusArray          = nil;
    self.ruleAgeArray       = nil;
}


- (NSInteger)cupMegahertzDescribeMoireImproperDownService:(StopSafetyMindCell *)newBarrage
{
    for (int row = 0; row<_ruleAgeArray.count; row++) {
        NSObject *object = _ruleAgeArray[row];
        if ([object isKindOfClass:[NSNumber class]]) { 
            
            return row;
            
        }else if ([object isKindOfClass:[StopSafetyMindCell class]]) { 
            
            StopSafetyMindCell *lowSupport = (StopSafetyMindCell*)object;
            
            if ([self cupMegahertzDescribeMoireImproperDownService:lowSupport metalBend:newBarrage]) {
                
                return row;
            }
        }
    }
    
    return -1;
}


- (BOOL)cupMegahertzDescribeMoireImproperDownService:(StopSafetyMindCell *)lowSupport metalBend:(StopSafetyMindCell *)newBarrage
{
    
    if (lowSupport.status == PortionEffortViabilitySalientReleasedArrival) {
        return NO;
    }
    
    
    CGRect rect = [lowSupport.layer.presentationLayer frame];
    if (rect.origin.x>CloseHalftone - lowSupport.frame.size.width) {
        
        return NO;
    }else if (rect.size.width == 0)
    {
        
        return NO;
    }
    else if (lowSupport.frame.size.width > newBarrage.frame.size.width) {
        
        return YES;
    }else
    {
        
        CGFloat time = CloseHalftone/(CloseHalftone+newBarrage.frame.size.width)*newBarrage.deferringWon;
        
        CGFloat grow = rect.origin.x - time/(lowSupport.deferringWon)*(CloseHalftone + lowSupport.frame.size.width);
        if (grow < -lowSupport.frame.size.width) {
            
            return YES;
        }
    }
    return NO;
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    CGPoint outHitPrep  = [touch locationInView:self];
    for (UIView *lighter in [self subviews])
    {
        if (![lighter isKindOfClass:[StopSafetyMindCell class]]) continue;
        StopSafetyMindCell *archeryView = (StopSafetyMindCell *)lighter;
        if ([archeryView.layer.presentationLayer hitTest:outHitPrep])
        {
            
            if ([self.delegate respondsToSelector:@selector(limitExceedsView:threeBinaryCell:)]) {
                [self.delegate limitExceedsView:self threeBinaryCell:archeryView];
            }
            break;
        }
    }
}




- (NSMutableArray<StopSafetyMindCell *> *)plusArray {
    if (!_plusArray) {
        _plusArray = [[NSMutableArray alloc] init];
    }
    return _plusArray;
}


- (NSMutableArray<StopSafetyMindCell *> *)illegalOuter {
    if (!_illegalOuter) {
        _illegalOuter = [[NSMutableArray alloc] init];
    }
    return _illegalOuter;
}


- (void)setChannelCount:(NSInteger)channelCount
{
    
    if (self.ruleAgeArray.count < channelCount) { 
        
        for (NSInteger row = self.ruleAgeArray.count; row < channelCount; row++) {
            NSNumber *number = [NSNumber numberWithBool:YES];
            [self.ruleAgeArray setObject:number atIndexedSubscript:row];
        }
        
    }else {
        
        for (NSInteger row = channelCount; row < self.ruleAgeArray.count; row++) {
            [self.ruleAgeArray removeObjectAtIndex:row];
        }
    }
    
    _channelCount = channelCount;
    
}


- (NSMutableArray *)ruleAgeArray {
    if (!_ruleAgeArray) {
        _ruleAgeArray = [[NSMutableArray alloc] init];
    }
    return _ruleAgeArray;
}

@end
