






#import "OptToast.h"
#import "TeaspoonsManager.h"


static UIColor *daughtersPreventDirectlyIndexesAdvancesColor = nil;
static UIColor *partOuterMayColor = nil;
static UIFont *tabUserDutch = nil;
static CGFloat trapMergeAlienRadius = 6.0;
static UIEdgeInsets digitTriggersRangeLowerFixInjection = {10, 16, 10, 16};

@interface OptToast()
@property (nonatomic, strong) UILabel *specifyLabel;
@property (nonatomic, strong) NSTimer *previewTimer;
@property (nonatomic, assign) BankAgentFlatUtilitiesUnlocked position;
@end

@implementation OptToast


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


+ (void)show:(NSString *)message
    duration:(NSTimeInterval)duration
    position:(BankAgentFlatUtilitiesUnlocked)position
{
    
    dispatch_async(dispatch_get_main_queue(), ^{
        OptToast *smart = [[OptToast alloc] initBlurMessage:message];
        smart.position = position;
        [smart sigmoidInstallsClickedPhaseSeventeen];
        [smart processMaleDecomposeHierarchyDivide:duration];
    });
}

- (void)processMaleDecomposeHierarchyDivide:(NSTimeInterval)duration {
    UIWindow *window = [TeaspoonsManager.shared ourHostPhaseWindow];
    [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 offsetsDeletionMixerPrivilegeMoreAnimation];
    
    
    if (duration > 0) {
        __weak typeof(self) weakSelf = self;
        self.previewTimer = [NSTimer scheduledTimerWithTimeInterval:duration repeats:YES block:^(NSTimer * _Nonnull bezel) {
            [weakSelf dismiss];
        }];
    }
}

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


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

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


- (void)sigmoidInstallsClickedPhaseSeventeen {
    UIView *container = self.specifyLabel.superview;
    
    
    switch (self.position) {
        case BeginSinFeaturesGetGopher: {
            [container.topAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.topAnchor
                                               constant:30].active = YES;
            break;
        }
        case CombiningPartOutMeasureAffectedCenter: {
            [container.centerYAnchor constraintEqualToAnchor:self.centerYAnchor].active = YES;
            break;
        }
        case FunctionsIgnoredAdjustPortalCursorHas: {
            [container.bottomAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.bottomAnchor
                                                  constant:-30].active = YES;
            break;
        }
    }
    
    
    [container.centerXAnchor constraintEqualToAnchor:self.centerXAnchor].active = YES;
}


+ (void)ascendingClockwiseLogoClampingWatchedRowsColor:(UIColor *)color {
    daughtersPreventDirectlyIndexesAdvancesColor = color;
}

+ (void)thumbChallengeColor:(UIColor *)color {
    partOuterMayColor = color;
}

+ (void)gainDetachRear:(UIFont *)font {
    tabUserDutch = font;
}

+ (void)carPriorLetterPhaseRevealRadius:(CGFloat)radius {
    trapMergeAlienRadius = radius;
}


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

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

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

- (void)dealloc {
    
}

@end
