






#import "YouToast.h"
#import "VortexBusManager.h"


static UIColor *howSaturateOldestTooEggColor = nil;
static UIColor *underlineSawColor = nil;
static UIFont *fetchedEight = nil;
static CGFloat ownArtSideLoopRadius = 6.0;
static UIEdgeInsets strongDeclinedBandValidityBrotherBed = {10, 16, 10, 16};

@interface YouToast()
@property (nonatomic, strong) UILabel *tooCapsLabel;
@property (nonatomic, strong) NSTimer *descentTimer;
@property (nonatomic, assign) WaxDeviceDominantPopHas position;
@end

@implementation YouToast


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


+ (void)show:(NSString *)message
    duration:(NSTimeInterval)duration
    position:(WaxDeviceDominantPopHas)position
{
    
    dispatch_async(dispatch_get_main_queue(), ^{
        YouToast *rebus = [[YouToast alloc] initFindMessage:message];
        rebus.position = position;
        [rebus bridgingWrappedHumidityDescribesGenerates];
        [rebus sinBoostTagFocusCommands:duration];
    });
}

- (void)sinBoostTagFocusCommands:(NSTimeInterval)duration {
    UIWindow *window = [VortexBusManager.shared broadcastOptWindow];
    [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 promotionCrossShowingLeaveAffineAnimation];
    
    
    if (duration > 0) {
        __weak typeof(self) weakSelf = self;
        self.descentTimer = [NSTimer scheduledTimerWithTimeInterval:duration repeats:YES block:^(NSTimer * _Nonnull pulse) {
            [weakSelf dismiss];
        }];
    }
}

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


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

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


- (void)bridgingWrappedHumidityDescribesGenerates {
    UIView *container = self.tooCapsLabel.superview;
    
    
    switch (self.position) {
        case DogRowsMeterBusySpecifier: {
            [container.topAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.topAnchor
                                               constant:30].active = YES;
            break;
        }
        case BeganMagentaListenerRunPetabytesCenter: {
            [container.centerYAnchor constraintEqualToAnchor:self.centerYAnchor].active = YES;
            break;
        }
        case HasWakeDirectoryPhoneBridgedBody: {
            [container.bottomAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.bottomAnchor
                                                  constant:-30].active = YES;
            break;
        }
    }
    
    
    [container.centerXAnchor constraintEqualToAnchor:self.centerXAnchor].active = YES;
}


+ (void)husbandAirlineUrgentRollbackSmallHisColor:(UIColor *)color {
    howSaturateOldestTooEggColor = color;
}

+ (void)adverbTailMathColor:(UIColor *)color {
    underlineSawColor = color;
}

+ (void)firstGetDayBag:(UIFont *)font {
    fetchedEight = font;
}

+ (void)memberLightenSensitiveLifetimeDividerRadius:(CGFloat)radius {
    ownArtSideLoopRadius = radius;
}


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

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

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

- (void)dealloc {
    
}

@end
