






#import "EraToast.h"
#import "StillSockManager.h"


static UIColor *extendingAboveAmountOperationStandardColor = nil;
static UIColor *escapesStoreColor = nil;
static UIFont *theSideMoire = nil;
static CGFloat notMinLoopFindRadius = 6.0;
static UIEdgeInsets allocatedDryRepeatExpertRelativeHex = {10, 16, 10, 16};

@interface EraToast()
@property (nonatomic, strong) UILabel *snapRawLabel;
@property (nonatomic, strong) NSTimer *spaHourTimer;
@property (nonatomic, assign) OldSeePingNowMill position;
@end

@implementation EraToast


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


+ (void)show:(NSString *)message
    duration:(NSTimeInterval)duration
    position:(OldSeePingNowMill)position
{
    
    dispatch_async(dispatch_get_main_queue(), ^{
        EraToast *quiet = [[EraToast alloc] initBothMessage:message];
        quiet.position = position;
        [quiet latvianTipMidCityLight];
        [quiet fadeNotCanPaperSchool:duration];
    });
}

- (void)fadeNotCanPaperSchool:(NSTimeInterval)duration {
    UIWindow *window = [StillSockManager.shared tenRomanCaseWindow];
    [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 runTwentyEachMenuEngineerAnimation];
    
    
    if (duration > 0) {
        __weak typeof(self) weakSelf = self;
        self.spaHourTimer = [NSTimer scheduledTimerWithTimeInterval:duration repeats:YES block:^(NSTimer * _Nonnull modal) {
            [weakSelf dismiss];
        }];
    }
}

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


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

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


- (void)latvianTipMidCityLight {
    UIView *container = self.snapRawLabel.superview;
    
    
    switch (self.position) {
        case DecisionCopticDuctilityKilovoltsYet: {
            [container.topAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.topAnchor
                                               constant:30].active = YES;
            break;
        }
        case WithinPipeCallPanoramasLibrariesCenter: {
            [container.centerYAnchor constraintEqualToAnchor:self.centerYAnchor].active = YES;
            break;
        }
        case KilowattsRunningUndefinedTipSimpleDriven: {
            [container.bottomAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.bottomAnchor
                                                  constant:-30].active = YES;
            break;
        }
    }
    
    
    [container.centerXAnchor constraintEqualToAnchor:self.centerXAnchor].active = YES;
}


+ (void)mainDeepCopperMidInteriorWarpColor:(UIColor *)color {
    extendingAboveAmountOperationStandardColor = color;
}

+ (void)leaveRemainingColor:(UIColor *)color {
    escapesStoreColor = color;
}

+ (void)mergeInserting:(UIFont *)font {
    theSideMoire = font;
}

+ (void)parentalEscapedCatUptimeManagersRadius:(CGFloat)radius {
    notMinLoopFindRadius = radius;
}


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

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

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

- (void)dealloc {
    
}

@end
