






#import "WetToast.h"
#import "WeekStripManager.h"


static UIColor *wayDingbatsMoveStormSodiumColor = nil;
static UIColor *barLevelRedoColor = nil;
static UIFont *insideHerMin = nil;
static CGFloat zoneHowDueWeekRadius = 6.0;
static UIEdgeInsets generateDiscardWriteKilovoltsFocusedDue = {10, 16, 10, 16};

@interface WetToast()
@property (nonatomic, strong) UILabel *fontKitLabel;
@property (nonatomic, strong) NSTimer *illTapsTimer;
@property (nonatomic, assign) MeterGrowListSleetException position;
@end

@implementation WetToast


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


+ (void)show:(NSString *)message
    duration:(NSTimeInterval)duration
    position:(MeterGrowListSleetException)position
{
    
    dispatch_async(dispatch_get_main_queue(), ^{
        WetToast *along = [[WetToast alloc] initStopMessage:message];
        along.position = position;
        [along appearGrandauntLabeledDisparityPast];
        [along trainingChainDeciliterFiltersCondensed:duration];
    });
}

- (void)trainingChainDeciliterFiltersCondensed:(NSTimeInterval)duration {
    UIWindow *window = [WeekStripManager.shared swipePenSideWindow];
    [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 brotherCutRecentlyStoreGeometricAnimation];
    
    
    if (duration > 0) {
        __weak typeof(self) weakSelf = self;
        self.illTapsTimer = [NSTimer scheduledTimerWithTimeInterval:duration repeats:YES block:^(NSTimer * _Nonnull visit) {
            [weakSelf dismiss];
        }];
    }
}

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


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

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


- (void)appearGrandauntLabeledDisparityPast {
    UIView *container = self.fontKitLabel.superview;
    
    
    switch (self.position) {
        case SmoothProductsSixteenGraySalient: {
            [container.topAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.topAnchor
                                               constant:30].active = YES;
            break;
        }
        case BookmarkCentralGravityTradStretchCenter: {
            [container.centerYAnchor constraintEqualToAnchor:self.centerYAnchor].active = YES;
            break;
        }
        case LargestAboutMoveServerReservedWarn: {
            [container.bottomAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.bottomAnchor
                                                  constant:-30].active = YES;
            break;
        }
    }
    
    
    [container.centerXAnchor constraintEqualToAnchor:self.centerXAnchor].active = YES;
}


+ (void)maxReportingWakePrimaryPaperInternetColor:(UIColor *)color {
    wayDingbatsMoveStormSodiumColor = color;
}

+ (void)dragPenDustHerColor:(UIColor *)color {
    barLevelRedoColor = color;
}

+ (void)panEarSexPatch:(UIFont *)font {
    insideHerMin = font;
}

+ (void)prototypeDescenderEmptyUbiquityKilobytesRadius:(CGFloat)radius {
    zoneHowDueWeekRadius = radius;
}


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

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

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

- (void)dealloc {
    
}

@end
