






#import "FarToast.h"
#import "StrictBigManager.h"


static UIColor *ruleLightenAdapterSheetEightColor = nil;
static UIColor *hasLongSigmaColor = nil;
static UIFont *copperRepeat = nil;
static CGFloat birthDayBoxDidRadius = 6.0;
static UIEdgeInsets nominalStartSlovenianLazyPartWeekend = {10, 16, 10, 16};

@interface FarToast()
@property (nonatomic, strong) UILabel *falloffLabel;
@property (nonatomic, strong) NSTimer *hexPoloTimer;
@property (nonatomic, assign) FavoriteSumForkExitsEnhance position;
@end

@implementation FarToast


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


+ (void)show:(NSString *)message
    duration:(NSTimeInterval)duration
    position:(FavoriteSumForkExitsEnhance)position
{
    
    dispatch_async(dispatch_get_main_queue(), ^{
        FarToast *bring = [[FarToast alloc] initInfoMessage:message];
        bring.position = position;
        [bring printerWorkoutDietaryGarbageAssistive];
        [bring viewTipNearbyBirthCalcium:duration];
    });
}

- (void)viewTipNearbyBirthCalcium:(NSTimeInterval)duration {
    UIWindow *window = [StrictBigManager.shared criteriaPushWindow];
    [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 vitaminMustExchangeSessionSpecificAnimation];
    
    
    if (duration > 0) {
        __weak typeof(self) weakSelf = self;
        self.hexPoloTimer = [NSTimer scheduledTimerWithTimeInterval:duration repeats:YES block:^(NSTimer * _Nonnull coast) {
            [weakSelf dismiss];
        }];
    }
}

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


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

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


- (void)printerWorkoutDietaryGarbageAssistive {
    UIView *container = self.falloffLabel.superview;
    
    
    switch (self.position) {
        case OriginsSinhaleseYouModelBulgarian: {
            [container.topAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.topAnchor
                                               constant:30].active = YES;
            break;
        }
        case ReviewDomainOverdueNoteRangeCenter: {
            [container.centerYAnchor constraintEqualToAnchor:self.centerYAnchor].active = YES;
            break;
        }
        case ExtrinsicAsleepLooseFileRateWarning: {
            [container.bottomAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.bottomAnchor
                                                  constant:-30].active = YES;
            break;
        }
    }
    
    
    [container.centerXAnchor constraintEqualToAnchor:self.centerXAnchor].active = YES;
}


+ (void)rebusRestoredContextsPosterLaunchTibetanColor:(UIColor *)color {
    ruleLightenAdapterSheetEightColor = color;
}

+ (void)cityStarDetachColor:(UIColor *)color {
    hasLongSigmaColor = color;
}

+ (void)baselineSlavic:(UIFont *)font {
    copperRepeat = font;
}

+ (void)teluguSuitableResumedBreakingMoveRadius:(CGFloat)radius {
    birthDayBoxDidRadius = radius;
}


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

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

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

- (void)dealloc {
    
}

@end
