








#import "TheSeeLostCrop.h"

#define ShowersRectum self.frame.size.width

@interface TheSeeLostCrop()



@property (nonatomic, strong) NSMutableArray                            *eastFarArray;



@property (nonatomic, strong) NSMutableArray <ClipSigmaDenseCell *>      *menuArray;



@property (strong, nonatomic) NSMutableArray <ClipSigmaDenseCell *>      *oddManSchool;



@property (assign, nonatomic) NSInteger                                 count;



@property (nonatomic, assign) WithTrailingFinalCervicalAppear                          status;



@property (nonatomic, assign) NSInteger                                 channelCount;



@property (nonatomic, assign) CGFloat                                   saySob;

@end

@implementation TheSeeLostCrop

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

- (void)midPartlyOne
{
    
    if (self.menuArray.firstObject) {
        
        
        ClipSigmaDenseCell *prepNotView = self.menuArray.firstObject;
        
        prepNotView.frame = CGRectMake(ShowersRectum, 0, prepNotView.chamberSize.width, prepNotView.chamberSize.height);
        
        self.saySob = prepNotView.saySob;
        
        self.channelCount = prepNotView.channelCount;
        
        
        NSInteger row = [self unboundedApplySelectorInvokeAxialTowerDirection:prepNotView];
        
        
        if (row >= 0) {
            
            
            [self.menuArray removeObjectAtIndex:0];
            
            
            if (![self.subviews containsObject:prepNotView]) {
                [self addSubview:prepNotView];
            }
            prepNotView.frame = CGRectMake(ShowersRectum,  row * (prepNotView.chamberSize.height + _saySob), prepNotView.chamberSize.width, prepNotView.chamberSize.height);
            
            
            [_eastFarArray setObject:prepNotView atIndexedSubscript:row];
            
            
            if ([self.delegate respondsToSelector:@selector(linkAskSoundView:willDisplayCell:)]) {
                [self.delegate linkAskSoundView:self willDisplayCell:prepNotView];
            }
            
            
            [self.oddManSchool addObject:prepNotView];
            
            [prepNotView insertionAdvancesRepeatFreezingDrop:^{
                
                
                [prepNotView setTransform:CGAffineTransformMakeTranslation(- prepNotView.frame.size.width-ShowersRectum, 0)];
                
            } completion:^(BOOL finished) {
                
                [prepNotView removeFromSuperview];
                
                
                [self.oddManSchool removeObject:prepNotView];
                
                
                if ([self.delegate respondsToSelector:@selector(linkAskSoundView:didEndDisplayingCell:)]) {
                    [self.delegate linkAskSoundView:self didEndDisplayingCell:prepNotView];
                }
                
                
                if (--self.count <= 0) {
                    if ([self.delegate respondsToSelector:@selector(overdueEighteenStampItsEstimatedWireRareLink:)]) {
                        [self.delegate overdueEighteenStampItsEstimatedWireRareLink:self];
                    }
                    self.count = 0;
                }
                
                

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


- (void)digestMinimize:(NSArray <ClipSigmaDenseCell *> *)barrages
{
    self.count += barrages.count;
    [self.menuArray addObjectsFromArray:barrages];
}

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

- (void)stop
{
    if (self.status == LogRestoringAirDeepApplyingConverted) {
        return;
    }
    self.status = LogRestoringAirDeepApplyingConverted;
    
    if (self.oddManSchool.count) {
        [self.oddManSchool makeObjectsPerformSelector:@selector(pause)];
    }
    
    if (self.menuArray.count > 0) {
        [NSObject cancelPreviousPerformRequestsWithTarget:self];
    }
    
    
    [self.oddManSchool  makeObjectsPerformSelector:@selector(removeFromSuperview)];
    self.channelCount       = 0;
    self.count              = 0;
    [self.oddManSchool  removeAllObjects];
    [self.menuArray     removeAllObjects];
    [self.eastFarArray  removeAllObjects];
    
    self.oddManSchool       = nil;
    self.menuArray          = nil;
    self.eastFarArray       = nil;
}


- (NSInteger)unboundedApplySelectorInvokeAxialTowerDirection:(ClipSigmaDenseCell *)newBarrage
{
    for (int row = 0; row<_eastFarArray.count; row++) {
        NSObject *object = _eastFarArray[row];
        if ([object isKindOfClass:[NSNumber class]]) { 
            
            return row;
            
        }else if ([object isKindOfClass:[ClipSigmaDenseCell class]]) { 
            
            ClipSigmaDenseCell *noneCloudy = (ClipSigmaDenseCell*)object;
            
            if ([self unboundedApplySelectorInvokeAxialTowerDirection:noneCloudy decayFork:newBarrage]) {
                
                return row;
            }
        }
    }
    
    return -1;
}


- (BOOL)unboundedApplySelectorInvokeAxialTowerDirection:(ClipSigmaDenseCell *)noneCloudy decayFork:(ClipSigmaDenseCell *)newBarrage
{
    
    if (noneCloudy.status == LooseLimitedMoreQuickSixteenKin) {
        return NO;
    }
    
    
    CGRect rect = [noneCloudy.layer.presentationLayer frame];
    if (rect.origin.x>ShowersRectum - noneCloudy.frame.size.width) {
        
        return NO;
    }else if (rect.size.width == 0)
    {
        
        return NO;
    }
    else if (noneCloudy.frame.size.width > newBarrage.frame.size.width) {
        
        return YES;
    }else
    {
        
        CGFloat time = ShowersRectum/(ShowersRectum+newBarrage.frame.size.width)*newBarrage.oddStepStart;
        
        CGFloat rope = rect.origin.x - time/(noneCloudy.oddStepStart)*(ShowersRectum + noneCloudy.frame.size.width);
        if (rope < -noneCloudy.frame.size.width) {
            
            return YES;
        }
    }
    return NO;
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    CGPoint lowForever  = [touch locationInView:self];
    for (UIView *jumpOpt in [self subviews])
    {
        if (![jumpOpt isKindOfClass:[ClipSigmaDenseCell class]]) continue;
        ClipSigmaDenseCell *prepNotView = (ClipSigmaDenseCell *)jumpOpt;
        if ([prepNotView.layer.presentationLayer hitTest:lowForever])
        {
            
            if ([self.delegate respondsToSelector:@selector(linkAskSoundView:cacheShrinkCell:)]) {
                [self.delegate linkAskSoundView:self cacheShrinkCell:prepNotView];
            }
            break;
        }
    }
}




- (NSMutableArray<ClipSigmaDenseCell *> *)menuArray {
    if (!_menuArray) {
        _menuArray = [[NSMutableArray alloc] init];
    }
    return _menuArray;
}


- (NSMutableArray<ClipSigmaDenseCell *> *)oddManSchool {
    if (!_oddManSchool) {
        _oddManSchool = [[NSMutableArray alloc] init];
    }
    return _oddManSchool;
}


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


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

@end
