






#import "ZipToast.h"
#import "TalkArrayManager.h"


static UIColor *molarCompletedLawExpansionCheckingColor = nil;
static UIColor *haveEyeBleedColor = nil;
static UIFont *greatSaveCap = nil;
static CGFloat blendSameHoverRadius = 6.0;
static UIEdgeInsets estimatedCatalanBypassIllSemicolonPlace = {10, 16, 10, 16};

@interface ZipToast()
@property (nonatomic, strong) UILabel *shuffleLabel;
@property (nonatomic, strong) NSTimer *revokedTimer;
@property (nonatomic, assign) PeakRelayFriendArchivedUsage position;
@end

@implementation ZipToast


- (instancetype)initLoopMessage:(NSString *)message {
    self = [super initWithFrame:CGRectZero];
    if (self) {
        self.userInteractionEnabled = NO;
        self.backgroundColor = UIColor.clearColor;
        
        
        UIView *container = [UIView new];
        container.backgroundColor = molarCompletedLawExpansionCheckingColor ?:
            [[UIColor blackColor] colorWithAlphaComponent:0.85];
        container.layer.cornerRadius = blendSameHoverRadius;
        container.clipsToBounds = YES;
        container.translatesAutoresizingMaskIntoConstraints = NO;
        [self addSubview:container];
        
        
        _shuffleLabel = [UILabel new];
        _shuffleLabel.text = message;
        _shuffleLabel.textColor = haveEyeBleedColor ?: UIColor.whiteColor;
        _shuffleLabel.font = greatSaveCap ?: [UIFont systemFontOfSize:14];
        _shuffleLabel.textAlignment = NSTextAlignmentCenter;
        _shuffleLabel.numberOfLines = 0;
        _shuffleLabel.translatesAutoresizingMaskIntoConstraints = NO;
        [container addSubview:_shuffleLabel];
        
        
        [NSLayoutConstraint activateConstraints:@[
            
            [container.leadingAnchor constraintEqualToAnchor:_shuffleLabel.leadingAnchor
                                                   constant:-estimatedCatalanBypassIllSemicolonPlace.left],
            [container.trailingAnchor constraintEqualToAnchor:_shuffleLabel.trailingAnchor
                                                    constant:estimatedCatalanBypassIllSemicolonPlace.right],
            [container.topAnchor constraintEqualToAnchor:_shuffleLabel.topAnchor
                                              constant:-estimatedCatalanBypassIllSemicolonPlace.top],
            [container.bottomAnchor constraintEqualToAnchor:_shuffleLabel.bottomAnchor
                                                 constant:estimatedCatalanBypassIllSemicolonPlace.bottom],
            
            
            [container.widthAnchor constraintLessThanOrEqualToConstant:
                [UIScreen mainScreen].bounds.size.width - 40]
        ]];
    }
    return self;
}


+ (void)show:(NSString *)message
    duration:(NSTimeInterval)duration
    position:(PeakRelayFriendArchivedUsage)position
{
    
    dispatch_async(dispatch_get_main_queue(), ^{
        ZipToast *under = [[ZipToast alloc] initLoopMessage:message];
        under.position = position;
        [under collapsedLazyResultsBoyfriendNorwegian];
        [under effectOppositeArrangerStoodFixing:duration];
    });
}

- (void)effectOppositeArrangerStoodFixing:(NSTimeInterval)duration {
    UIWindow *window = [TalkArrayManager.shared oceanIntegerWindow];
    [window addSubview:self];
    
    
    self.translatesAutoresizingMaskIntoConstraints = NO;
    [NSLayoutConstraint activateConstraints:@[
        [self.leadingAnchor constraintEqualToAnchor:window.leadingAnchor],
        [self.trailingAnchor constraintEqualToAnchor:window.trailingAnchor],
        [self.topAnchor constraintEqualToAnchor:window.topAnchor],
        [self.bottomAnchor constraintEqualToAnchor:window.bottomAnchor]
    ]];
    
    
    [self restartBinSynthesisDirectionSubfamilyAnimation];
    
    
    if (duration > 0) {
        __weak typeof(self) weakSelf = self;
        self.revokedTimer = [NSTimer scheduledTimerWithTimeInterval:duration repeats:YES block:^(NSTimer * _Nonnull foggy) {
            [weakSelf dismiss];
        }];
    }
}

- (void)dismiss {
    [self.revokedTimer invalidate];
    [self echoSampleMoreFloatPeopleHighestOperator:^{
        [self removeFromSuperview];
    }];
}


- (void)restartBinSynthesisDirectionSubfamilyAnimation {
    CGAffineTransform transform;
    switch (self.position) {
        case TeamDefinesBagReplaceWho:
            transform = CGAffineTransformMakeTranslation(0, -100);
            break;
        case JustFeedArmpitSummariesNumeralParser:
            transform = CGAffineTransformMakeTranslation(0, 100);
            break;
        default:
            transform = CGAffineTransformMakeScale(0.8, 0.8);
            break;
    }
    
    self.alpha = 0;
    self.shuffleLabel.superview.transform = transform;
    
    [UIView animateWithDuration:0.3
                          delay:0
         usingSpringWithDamping:0.7
          initialSpringVelocity:0.1
                        options:UIViewAnimationOptionCurveEaseOut
                     animations:^{
        self.alpha = 1;
        self.shuffleLabel.superview.transform = CGAffineTransformIdentity;
    } completion:nil];
}

- (void)echoSampleMoreFloatPeopleHighestOperator:(void(^)(void))completion {
    CGAffineTransform transform;
    switch (self.position) {
        case TeamDefinesBagReplaceWho:
            transform = CGAffineTransformMakeTranslation(0, -self.shuffleLabel.superview.frame.size.height - 50);
            break;
        case JustFeedArmpitSummariesNumeralParser:
            transform = CGAffineTransformMakeTranslation(0, self.shuffleLabel.superview.frame.size.height + 50);
            break;
        default:
            transform = CGAffineTransformMakeScale(0.8, 0.8);
            break;
    }
    
    [UIView animateWithDuration:0.25
                     animations:^{
        self.alpha = 0;
        self.shuffleLabel.superview.transform = transform;
    } completion:^(BOOL finished) {
        if (completion) completion();
    }];
}


- (void)collapsedLazyResultsBoyfriendNorwegian {
    UIView *container = self.shuffleLabel.superview;
    
    
    switch (self.position) {
        case TeamDefinesBagReplaceWho: {
            [container.topAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.topAnchor
                                               constant:30].active = YES;
            break;
        }
        case HeavyReversedAlphabetInterConfigureCenter: {
            [container.centerYAnchor constraintEqualToAnchor:self.centerYAnchor].active = YES;
            break;
        }
        case JustFeedArmpitSummariesNumeralParser: {
            [container.bottomAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.bottomAnchor
                                                  constant:-30].active = YES;
            break;
        }
    }
    
    
    [container.centerXAnchor constraintEqualToAnchor:self.centerXAnchor].active = YES;
}


+ (void)unlockPressedKilowattInteriorFactoriesFormatColor:(UIColor *)color {
    molarCompletedLawExpansionCheckingColor = color;
}

+ (void)potassiumWhiteColor:(UIColor *)color {
    haveEyeBleedColor = color;
}

+ (void)partLegacyHand:(UIFont *)font {
    greatSaveCap = font;
}

+ (void)completedDueSumTemporalVortexRadius:(CGFloat)radius {
    blendSameHoverRadius = radius;
}


+ (void)zipFlat:(NSString *)message {
    [self show:message duration:2.0 position:TeamDefinesBagReplaceWho];
}

+ (void)passCenter:(NSString *)message {
    [self show:message duration:2.0 position:HeavyReversedAlphabetInterConfigureCenter];
}

+ (void)dryFaxOnce:(NSString *)message {
    [self show:message duration:2.0 position:JustFeedArmpitSummariesNumeralParser];
}

- (void)dealloc {
    
}

@end
