








#import "PascalExternal.h"

#define BinFaxTwitter self.frame.size.width

@interface PascalExternal()



@property (nonatomic, strong) NSMutableArray                            *primaryArray;



@property (nonatomic, strong) NSMutableArray <RouteCaseArrayCell *>      *peakArray;



@property (strong, nonatomic) NSMutableArray <RouteCaseArrayCell *>      *bagWrapApple;



@property (assign, nonatomic) NSInteger                                 count;



@property (nonatomic, assign) HaveWonLightSelectionFoot                          status;



@property (nonatomic, assign) NSInteger                                 channelCount;



@property (nonatomic, assign) CGFloat                                   oxygen;

@end

@implementation PascalExternal

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

- (void)tapBridgeSub
{
    
    if (self.peakArray.firstObject) {
        
        
        RouteCaseArrayCell *runningView = self.peakArray.firstObject;
        
        runningView.frame = CGRectMake(BinFaxTwitter, 0, runningView.musicalSize.width, runningView.musicalSize.height);
        
        self.oxygen = runningView.oxygen;
        
        self.channelCount = runningView.channelCount;
        
        
        NSInteger row = [self intentsIndexesLookHasPlacementSpringPin:runningView];
        
        
        if (row >= 0) {
            
            
            [self.peakArray removeObjectAtIndex:0];
            
            
            if (![self.subviews containsObject:runningView]) {
                [self addSubview:runningView];
            }
            runningView.frame = CGRectMake(BinFaxTwitter,  row * (runningView.musicalSize.height + _oxygen), runningView.musicalSize.width, runningView.musicalSize.height);
            
            
            [_primaryArray setObject:runningView atIndexedSubscript:row];
            
            
            if ([self.delegate respondsToSelector:@selector(lowercaseFitView:willDisplayCell:)]) {
                [self.delegate lowercaseFitView:self willDisplayCell:runningView];
            }
            
            
            [self.bagWrapApple addObject:runningView];
            
            [runningView attitudeSaveNowDeleteSafe:^{
                
                
                [runningView setTransform:CGAffineTransformMakeTranslation(- runningView.frame.size.width-BinFaxTwitter, 0)];
                
            } completion:^(BOOL finished) {
                
                [runningView removeFromSuperview];
                
                
                [self.bagWrapApple removeObject:runningView];
                
                
                if ([self.delegate respondsToSelector:@selector(lowercaseFitView:didEndDisplayingCell:)]) {
                    [self.delegate lowercaseFitView:self didEndDisplayingCell:runningView];
                }
                
                
                if (--self.count <= 0) {
                    if ([self.delegate respondsToSelector:@selector(recorderLoopRenewalCupRawCanonicalPolicyWet:)]) {
                        [self.delegate recorderLoopRenewalCupRawCanonicalPolicyWet:self];
                    }
                    self.count = 0;
                }
                
                

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


- (void)exactMagicFire:(NSArray <RouteCaseArrayCell *> *)barrages
{
    self.count += barrages.count;
    [self.peakArray addObjectsFromArray:barrages];
}

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

- (void)stop
{
    if (self.status == SelectorEmergencyOrderingSonFoundEffort) {
        return;
    }
    self.status = SelectorEmergencyOrderingSonFoundEffort;
    
    if (self.bagWrapApple.count) {
        [self.bagWrapApple makeObjectsPerformSelector:@selector(pause)];
    }
    
    if (self.peakArray.count > 0) {
        [NSObject cancelPreviousPerformRequestsWithTarget:self];
    }
    
    
    [self.bagWrapApple  makeObjectsPerformSelector:@selector(removeFromSuperview)];
    self.channelCount       = 0;
    self.count              = 0;
    [self.bagWrapApple  removeAllObjects];
    [self.peakArray     removeAllObjects];
    [self.primaryArray  removeAllObjects];
    
    self.bagWrapApple       = nil;
    self.peakArray          = nil;
    self.primaryArray       = nil;
}


- (NSInteger)intentsIndexesLookHasPlacementSpringPin:(RouteCaseArrayCell *)newBarrage
{
    for (int row = 0; row<_primaryArray.count; row++) {
        NSObject *object = _primaryArray[row];
        if ([object isKindOfClass:[NSNumber class]]) { 
            
            return row;
            
        }else if ([object isKindOfClass:[RouteCaseArrayCell class]]) { 
            
            RouteCaseArrayCell *decideBurn = (RouteCaseArrayCell*)object;
            
            if ([self intentsIndexesLookHasPlacementSpringPin:decideBurn underFast:newBarrage]) {
                
                return row;
            }
        }
    }
    
    return -1;
}


- (BOOL)intentsIndexesLookHasPlacementSpringPin:(RouteCaseArrayCell *)decideBurn underFast:(RouteCaseArrayCell *)newBarrage
{
    
    if (decideBurn.status == FocusingMouthUnwrapCompanyLevelExpected) {
        return NO;
    }
    
    
    CGRect rect = [decideBurn.layer.presentationLayer frame];
    if (rect.origin.x>BinFaxTwitter - decideBurn.frame.size.width) {
        
        return NO;
    }else if (rect.size.width == 0)
    {
        
        return NO;
    }
    else if (decideBurn.frame.size.width > newBarrage.frame.size.width) {
        
        return YES;
    }else
    {
        
        CGFloat time = BinFaxTwitter/(BinFaxTwitter+newBarrage.frame.size.width)*newBarrage.sunCycleGrow;
        
        CGFloat snow = rect.origin.x - time/(decideBurn.sunCycleGrow)*(BinFaxTwitter + decideBurn.frame.size.width);
        if (snow < -decideBurn.frame.size.width) {
            
            return YES;
        }
    }
    return NO;
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    CGPoint excludeKey  = [touch locationInView:self];
    for (UIView *hexMole in [self subviews])
    {
        if (![hexMole isKindOfClass:[RouteCaseArrayCell class]]) continue;
        RouteCaseArrayCell *runningView = (RouteCaseArrayCell *)hexMole;
        if ([runningView.layer.presentationLayer hitTest:excludeKey])
        {
            
            if ([self.delegate respondsToSelector:@selector(lowercaseFitView:twoCertNineCell:)]) {
                [self.delegate lowercaseFitView:self twoCertNineCell:runningView];
            }
            break;
        }
    }
}




- (NSMutableArray<RouteCaseArrayCell *> *)peakArray {
    if (!_peakArray) {
        _peakArray = [[NSMutableArray alloc] init];
    }
    return _peakArray;
}


- (NSMutableArray<RouteCaseArrayCell *> *)bagWrapApple {
    if (!_bagWrapApple) {
        _bagWrapApple = [[NSMutableArray alloc] init];
    }
    return _bagWrapApple;
}


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


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

@end
