








#import "SaturatedShake.h"

#define AwayInserting self.frame.size.width

@interface SaturatedShake()



@property (nonatomic, strong) NSMutableArray                            *outsideArray;



@property (nonatomic, strong) NSMutableArray <WaterMayWhoEarCell *>      *warnArray;



@property (strong, nonatomic) NSMutableArray <WaterMayWhoEarCell *>      *cupAxialNear;



@property (assign, nonatomic) NSInteger                                 count;



@property (nonatomic, assign) CatInterRequirePongLimit                          status;



@property (nonatomic, assign) NSInteger                                 channelCount;



@property (nonatomic, assign) CGFloat                                   eleven;

@end

@implementation SaturatedShake

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

- (void)toolLegalCap
{
    
    if (self.warnArray.firstObject) {
        
        
        WaterMayWhoEarCell *cellSobView = self.warnArray.firstObject;
        
        cellSobView.frame = CGRectMake(AwayInserting, 0, cellSobView.startupSize.width, cellSobView.startupSize.height);
        
        self.eleven = cellSobView.eleven;
        
        self.channelCount = cellSobView.channelCount;
        
        
        NSInteger row = [self legacyGlobalIntentMasterPromisedCapEgg:cellSobView];
        
        
        if (row >= 0) {
            
            
            [self.warnArray removeObjectAtIndex:0];
            
            
            if (![self.subviews containsObject:cellSobView]) {
                [self addSubview:cellSobView];
            }
            cellSobView.frame = CGRectMake(AwayInserting,  row * (cellSobView.startupSize.height + _eleven), cellSobView.startupSize.width, cellSobView.startupSize.height);
            
            
            [_outsideArray setObject:cellSobView atIndexedSubscript:row];
            
            
            if ([self.delegate respondsToSelector:@selector(callHitRoundView:willDisplayCell:)]) {
                [self.delegate callHitRoundView:self willDisplayCell:cellSobView];
            }
            
            
            [self.cupAxialNear addObject:cellSobView];
            
            [cellSobView refusedNextIntroCupBurn:^{
                
                
                [cellSobView setTransform:CGAffineTransformMakeTranslation(- cellSobView.frame.size.width-AwayInserting, 0)];
                
            } completion:^(BOOL finished) {
                
                [cellSobView removeFromSuperview];
                
                
                [self.cupAxialNear removeObject:cellSobView];
                
                
                if ([self.delegate respondsToSelector:@selector(callHitRoundView:didEndDisplayingCell:)]) {
                    [self.delegate callHitRoundView:self didEndDisplayingCell:cellSobView];
                }
                
                
                if (--self.count <= 0) {
                    if ([self.delegate respondsToSelector:@selector(chargeFavoritesDetachCourseLeastDeliveredLemmaDouble:)]) {
                        [self.delegate chargeFavoritesDetachCourseLeastDeliveredLemmaDouble:self];
                    }
                    self.count = 0;
                }
                
                

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


- (void)redirectsSleet:(NSArray <WaterMayWhoEarCell *> *)barrages
{
    self.count += barrages.count;
    [self.warnArray addObjectsFromArray:barrages];
}

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

- (void)stop
{
    if (self.status == CallbacksHoldSmallHailUniformHeadline) {
        return;
    }
    self.status = CallbacksHoldSmallHailUniformHeadline;
    
    if (self.cupAxialNear.count) {
        [self.cupAxialNear makeObjectsPerformSelector:@selector(pause)];
    }
    
    if (self.warnArray.count > 0) {
        [NSObject cancelPreviousPerformRequestsWithTarget:self];
    }
    
    
    [self.cupAxialNear  makeObjectsPerformSelector:@selector(removeFromSuperview)];
    self.channelCount       = 0;
    self.count              = 0;
    [self.cupAxialNear  removeAllObjects];
    [self.warnArray     removeAllObjects];
    [self.outsideArray  removeAllObjects];
    
    self.cupAxialNear       = nil;
    self.warnArray          = nil;
    self.outsideArray       = nil;
}


- (NSInteger)legacyGlobalIntentMasterPromisedCapEgg:(WaterMayWhoEarCell *)newBarrage
{
    for (int row = 0; row<_outsideArray.count; row++) {
        NSObject *object = _outsideArray[row];
        if ([object isKindOfClass:[NSNumber class]]) { 
            
            return row;
            
        }else if ([object isKindOfClass:[WaterMayWhoEarCell class]]) { 
            
            WaterMayWhoEarCell *pintResume = (WaterMayWhoEarCell*)object;
            
            if ([self legacyGlobalIntentMasterPromisedCapEgg:pintResume revisions:newBarrage]) {
                
                return row;
            }
        }
    }
    
    return -1;
}


- (BOOL)legacyGlobalIntentMasterPromisedCapEgg:(WaterMayWhoEarCell *)pintResume revisions:(WaterMayWhoEarCell *)newBarrage
{
    
    if (pintResume.status == ManganeseMinTeaspoonsCountAlphaPortrait) {
        return NO;
    }
    
    
    CGRect rect = [pintResume.layer.presentationLayer frame];
    if (rect.origin.x>AwayInserting - pintResume.frame.size.width) {
        
        return NO;
    }else if (rect.size.width == 0)
    {
        
        return NO;
    }
    else if (pintResume.frame.size.width > newBarrage.frame.size.width) {
        
        return YES;
    }else
    {
        
        CGFloat time = AwayInserting/(AwayInserting+newBarrage.frame.size.width)*newBarrage.landscapeDog;
        
        CGFloat walk = rect.origin.x - time/(pintResume.landscapeDog)*(AwayInserting + pintResume.frame.size.width);
        if (walk < -pintResume.frame.size.width) {
            
            return YES;
        }
    }
    return NO;
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    UITouch *hover = [touches anyObject];
    CGPoint jumpTipFar  = [hover locationInView:self];
    for (UIView *peakTap in [self subviews])
    {
        if (![peakTap isKindOfClass:[WaterMayWhoEarCell class]]) continue;
        WaterMayWhoEarCell *cellSobView = (WaterMayWhoEarCell *)peakTap;
        if ([cellSobView.layer.presentationLayer hitTest:jumpTipFar])
        {
            
            if ([self.delegate respondsToSelector:@selector(callHitRoundView:tipSigmaBagCell:)]) {
                [self.delegate callHitRoundView:self tipSigmaBagCell:cellSobView];
            }
            break;
        }
    }
}




- (NSMutableArray<WaterMayWhoEarCell *> *)warnArray {
    if (!_warnArray) {
        _warnArray = [[NSMutableArray alloc] init];
    }
    return _warnArray;
}


- (NSMutableArray<WaterMayWhoEarCell *> *)cupAxialNear {
    if (!_cupAxialNear) {
        _cupAxialNear = [[NSMutableArray alloc] init];
    }
    return _cupAxialNear;
}


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


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

@end
