






#import "DryToast.h"
#import "PredicateManager.h"


static UIColor *surgeLanguagesFocalDrizzleBalancedColor = nil;
static UIColor *flashPressesColor = nil;
static UIFont *earNotFuture = nil;
static CGFloat fireAlienRightRadius = 6.0;
static UIEdgeInsets forbidResultCanMixMandarinTrusted = {10, 16, 10, 16};

@interface DryToast()
@property (nonatomic, strong) UILabel *overageLabel;
@property (nonatomic, strong) NSTimer *makeCutTimer;
@property (nonatomic, assign) WristConstructBoundSequenceCocoa position;
@end

@implementation DryToast


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


+ (void)show:(NSString *)message
    duration:(NSTimeInterval)duration
    position:(WristConstructBoundSequenceCocoa)position
{
    
    dispatch_async(dispatch_get_main_queue(), ^{
        DryToast *arrow = [[DryToast alloc] initWithMessage:message];
        arrow.position = position;
        [arrow mindfulFragmentsCurveLookupPub];
        [arrow inhalerUpscaleSameCaptionReference:duration];
    });
}

- (void)inhalerUpscaleSameCaptionReference:(NSTimeInterval)duration {
    UIWindow *window = [PredicateManager.shared companyLeakyWindow];
    [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 maintainSunYouInviteeDanceAnimation];
    
    
    if (duration > 0) {
        __weak typeof(self) weakSelf = self;
        self.makeCutTimer = [NSTimer scheduledTimerWithTimeInterval:duration repeats:YES block:^(NSTimer * _Nonnull awake) {
            [weakSelf dismiss];
        }];
    }
}

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


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

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


- (void)mindfulFragmentsCurveLookupPub {
    UIView *container = self.overageLabel.superview;
    
    
    switch (self.position) {
        case ParentUnwindPhraseEqualityManaged: {
            [container.topAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.topAnchor
                                               constant:30].active = YES;
            break;
        }
        case UnlearnBottomOperatingSobErrorCenter: {
            [container.centerYAnchor constraintEqualToAnchor:self.centerYAnchor].active = YES;
            break;
        }
        case AdoptMirroringFaceSubstringLoadingAlbum: {
            [container.bottomAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.bottomAnchor
                                                  constant:-30].active = YES;
            break;
        }
    }
    
    
    [container.centerXAnchor constraintEqualToAnchor:self.centerXAnchor].active = YES;
}


+ (void)resultsCarrierIncludingSamplingIdentifyBaselinesColor:(UIColor *)color {
    surgeLanguagesFocalDrizzleBalancedColor = color;
}

+ (void)literElevationColor:(UIColor *)color {
    flashPressesColor = color;
}

+ (void)snowOurSobFile:(UIFont *)font {
    earNotFuture = font;
}

+ (void)millibarsCanceledUpdateCombiningBringRadius:(CGFloat)radius {
    fireAlienRightRadius = radius;
}


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

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

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

- (void)dealloc {
    
}

@end
