








#import "FlipPackMarkup.h"

#define BadMatchAngle self.frame.size.width

@interface FlipPackMarkup()



@property (nonatomic, strong) NSMutableArray                            *moreSayArray;



@property (nonatomic, strong) NSMutableArray <LostSendNegateCell *>      *artsArray;



@property (strong, nonatomic) NSMutableArray <LostSendNegateCell *>      *ourLayoutMay;



@property (assign, nonatomic) NSInteger                                 count;



@property (nonatomic, assign) ModifiersHomepageConfirmAllGradient                          status;



@property (nonatomic, assign) NSInteger                                 channelCount;



@property (nonatomic, assign) CGFloat                                   bridge;

@end

@implementation FlipPackMarkup

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

- (void)setupPackage
{
    
    if (self.artsArray.firstObject) {
        
        
        LostSendNegateCell *insulinView = self.artsArray.firstObject;
        
        insulinView.frame = CGRectMake(BadMatchAngle, 0, insulinView.forStopSize.width, insulinView.forStopSize.height);
        
        self.bridge = insulinView.bridge;
        
        self.channelCount = insulinView.channelCount;
        
        
        NSInteger row = [self sandboxHisCancelingSleepCanonicalImproperStation:insulinView];
        
        
        if (row >= 0) {
            
            
            [self.artsArray removeObjectAtIndex:0];
            
            
            if (![self.subviews containsObject:insulinView]) {
                [self addSubview:insulinView];
            }
            insulinView.frame = CGRectMake(BadMatchAngle,  row * (insulinView.forStopSize.height + _bridge), insulinView.forStopSize.width, insulinView.forStopSize.height);
            
            
            [_moreSayArray setObject:insulinView atIndexedSubscript:row];
            
            
            if ([self.delegate respondsToSelector:@selector(armHungarianView:willDisplayCell:)]) {
                [self.delegate armHungarianView:self willDisplayCell:insulinView];
            }
            
            
            [self.ourLayoutMay addObject:insulinView];
            
            [insulinView atomicGetResizingLabelBook:^{
                
                
                [insulinView setTransform:CGAffineTransformMakeTranslation(- insulinView.frame.size.width-BadMatchAngle, 0)];
                
            } completion:^(BOOL finished) {
                
                [insulinView removeFromSuperview];
                
                
                [self.ourLayoutMay removeObject:insulinView];
                
                
                if ([self.delegate respondsToSelector:@selector(armHungarianView:didEndDisplayingCell:)]) {
                    [self.delegate armHungarianView:self didEndDisplayingCell:insulinView];
                }
                
                
                if (--self.count <= 0) {
                    if ([self.delegate respondsToSelector:@selector(remotelyExpandedMilesMediaBalticSinRefusedFolder:)]) {
                        [self.delegate remotelyExpandedMilesMediaBalticSinRefusedFolder:self];
                    }
                    self.count = 0;
                }
                
                

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


- (void)mileFarMathBed:(NSArray <LostSendNegateCell *> *)barrages
{
    self.count += barrages.count;
    [self.artsArray addObjectsFromArray:barrages];
}

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

- (void)stop
{
    if (self.status == OffDecodingSplitNapPersonalAssamese) {
        return;
    }
    self.status = OffDecodingSplitNapPersonalAssamese;
    
    if (self.ourLayoutMay.count) {
        [self.ourLayoutMay makeObjectsPerformSelector:@selector(pause)];
    }
    
    if (self.artsArray.count > 0) {
        [NSObject cancelPreviousPerformRequestsWithTarget:self];
    }
    
    
    [self.ourLayoutMay  makeObjectsPerformSelector:@selector(removeFromSuperview)];
    self.channelCount       = 0;
    self.count              = 0;
    [self.ourLayoutMay  removeAllObjects];
    [self.artsArray     removeAllObjects];
    [self.moreSayArray  removeAllObjects];
    
    self.ourLayoutMay       = nil;
    self.artsArray          = nil;
    self.moreSayArray       = nil;
}


- (NSInteger)sandboxHisCancelingSleepCanonicalImproperStation:(LostSendNegateCell *)newBarrage
{
    for (int row = 0; row<_moreSayArray.count; row++) {
        NSObject *object = _moreSayArray[row];
        if ([object isKindOfClass:[NSNumber class]]) { 
            
            return row;
            
        }else if ([object isKindOfClass:[LostSendNegateCell class]]) { 
            
            LostSendNegateCell *affineWith = (LostSendNegateCell*)object;
            
            if ([self sandboxHisCancelingSleepCanonicalImproperStation:affineWith reasonOut:newBarrage]) {
                
                return row;
            }
        }
    }
    
    return -1;
}


- (BOOL)sandboxHisCancelingSleepCanonicalImproperStation:(LostSendNegateCell *)affineWith reasonOut:(LostSendNegateCell *)newBarrage
{
    
    if (affineWith.status == ModeIncorrectNameParserUploadOur) {
        return NO;
    }
    
    
    CGRect rect = [affineWith.layer.presentationLayer frame];
    if (rect.origin.x>BadMatchAngle - affineWith.frame.size.width) {
        
        return NO;
    }else if (rect.size.width == 0)
    {
        
        return NO;
    }
    else if (affineWith.frame.size.width > newBarrage.frame.size.width) {
        
        return YES;
    }else
    {
        
        CGFloat time = BadMatchAngle/(BadMatchAngle+newBarrage.frame.size.width)*newBarrage.sindhiWayHas;
        
        CGFloat curl = rect.origin.x - time/(affineWith.sindhiWayHas)*(BadMatchAngle + affineWith.frame.size.width);
        if (curl < -affineWith.frame.size.width) {
            
            return YES;
        }
    }
    return NO;
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    UITouch *space = [touches anyObject];
    CGPoint inlandEdga  = [space locationInView:self];
    for (UIView *tooSock in [self subviews])
    {
        if (![tooSock isKindOfClass:[LostSendNegateCell class]]) continue;
        LostSendNegateCell *insulinView = (LostSendNegateCell *)tooSock;
        if ([insulinView.layer.presentationLayer hitTest:inlandEdga])
        {
            
            if ([self.delegate respondsToSelector:@selector(armHungarianView:hashForSinkCell:)]) {
                [self.delegate armHungarianView:self hashForSinkCell:insulinView];
            }
            break;
        }
    }
}




- (NSMutableArray<LostSendNegateCell *> *)artsArray {
    if (!_artsArray) {
        _artsArray = [[NSMutableArray alloc] init];
    }
    return _artsArray;
}


- (NSMutableArray<LostSendNegateCell *> *)ourLayoutMay {
    if (!_ourLayoutMay) {
        _ourLayoutMay = [[NSMutableArray alloc] init];
    }
    return _ourLayoutMay;
}


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


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

@end
