






#import "PutToast.h"
#import "CountHostManager.h"


static UIColor *deliverZoneRevealedPeriodicIndexColor = nil;
static UIColor *caffeineRateColor = nil;
static UIFont *trapDefaults = nil;
static CGFloat fullyLowHisWayRadius = 6.0;
static UIEdgeInsets staleSpaPeopleSoloistReflectBirth = {10, 16, 10, 16};

@interface PutToast()
@property (nonatomic, strong) UILabel *neutralLabel;
@property (nonatomic, strong) NSTimer *tagLazyTimer;
@property (nonatomic, assign) BoundaryShutdownSemicolonTheElectric position;
@end

@implementation PutToast


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


+ (void)show:(NSString *)message
    duration:(NSTimeInterval)duration
    position:(BoundaryShutdownSemicolonTheElectric)position
{
    
    dispatch_async(dispatch_get_main_queue(), ^{
        PutToast *every = [[PutToast alloc] initRootMessage:message];
        every.position = position;
        [every undoSaltOwnerCreatedOdd];
        [every positionsMixProcessNotLease:duration];
    });
}

- (void)positionsMixProcessNotLease:(NSTimeInterval)duration {
    UIWindow *window = [CountHostManager.shared maxForceDarkWindow];
    [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 slashesNetDistinctDefaultEventAnimation];
    
    
    if (duration > 0) {
        __weak typeof(self) weakSelf = self;
        self.tagLazyTimer = [NSTimer scheduledTimerWithTimeInterval:duration repeats:YES block:^(NSTimer * _Nonnull molar) {
            [weakSelf dismiss];
        }];
    }
}

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


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

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


- (void)undoSaltOwnerCreatedOdd {
    UIView *container = self.neutralLabel.superview;
    
    
    switch (self.position) {
        case WeightedWrestlingPeriodFontDefine: {
            [container.topAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.topAnchor
                                               constant:30].active = YES;
            break;
        }
        case DefineSlantLongestSwipeGenericsCenter: {
            [container.centerYAnchor constraintEqualToAnchor:self.centerYAnchor].active = YES;
            break;
        }
        case ConfigureSymptomComplexWaterMusicianPascal: {
            [container.bottomAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.bottomAnchor
                                                  constant:-30].active = YES;
            break;
        }
    }
    
    
    [container.centerXAnchor constraintEqualToAnchor:self.centerXAnchor].active = YES;
}


+ (void)checkoutSaltHisSoftAmpereIntervalsColor:(UIColor *)color {
    deliverZoneRevealedPeriodicIndexColor = color;
}

+ (void)floatExportingColor:(UIColor *)color {
    caffeineRateColor = color;
}

+ (void)realCupScanHis:(UIFont *)font {
    trapDefaults = font;
}

+ (void)walkWorkoutsCrossOddAnimatedRadius:(CGFloat)radius {
    fullyLowHisWayRadius = radius;
}


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

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

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

- (void)dealloc {
    
}

@end
