






#import "FarToast.h"
#import "AboutLikeManager.h"


static UIColor *makerLimitLiterManagersCoulombsColor = nil;
static UIColor *matchBuilderColor = nil;
static UIFont *peerSeeUpper = nil;
static CGFloat utilityTornadoRadius = 6.0;
static UIEdgeInsets equalitySplatDisposeBeginForeverTeaspoons = {10, 16, 10, 16};

@interface FarToast()
@property (nonatomic, strong) UILabel *corruptLabel;
@property (nonatomic, strong) NSTimer *tooExecTimer;
@property (nonatomic, assign) PortionPlayingFatBiotinRanked position;
@end

@implementation FarToast


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


+ (void)show:(NSString *)message
    duration:(NSTimeInterval)duration
    position:(PortionPlayingFatBiotinRanked)position
{
    
    dispatch_async(dispatch_get_main_queue(), ^{
        FarToast *glyph = [[FarToast alloc] initMealMessage:message];
        glyph.position = position;
        [glyph provideAcrossCorrectedMixFun];
        [glyph subtitlesAgreementCatTeethSuch:duration];
    });
}

- (void)subtitlesAgreementCatTeethSuch:(NSTimeInterval)duration {
    UIWindow *window = [AboutLikeManager.shared scriptRhythmWindow];
    [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 ascentGradientReceivingIodineRedAnimation];
    
    
    if (duration > 0) {
        __weak typeof(self) weakSelf = self;
        self.tooExecTimer = [NSTimer scheduledTimerWithTimeInterval:duration repeats:YES block:^(NSTimer * _Nonnull spine) {
            [weakSelf dismiss];
        }];
    }
}

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


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

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


- (void)provideAcrossCorrectedMixFun {
    UIView *container = self.corruptLabel.superview;
    
    
    switch (self.position) {
        case ButSerializeFaxLeftMap: {
            [container.topAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.topAnchor
                                               constant:30].active = YES;
            break;
        }
        case ProgressGallonsItsHaveListenersCenter: {
            [container.centerYAnchor constraintEqualToAnchor:self.centerYAnchor].active = YES;
            break;
        }
        case SharpnessEntitledHeapLinkageAboveSignal: {
            [container.bottomAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.bottomAnchor
                                                  constant:-30].active = YES;
            break;
        }
    }
    
    
    [container.centerXAnchor constraintEqualToAnchor:self.centerXAnchor].active = YES;
}


+ (void)divideSeekRespondsCatStepchildMusicColor:(UIColor *)color {
    makerLimitLiterManagersCoulombsColor = color;
}

+ (void)manClickArtBoxColor:(UIColor *)color {
    matchBuilderColor = color;
}

+ (void)tailLawDayHalf:(UIFont *)font {
    peerSeeUpper = font;
}

+ (void)peopleTripleExpandingHeightZoomRadius:(CGFloat)radius {
    utilityTornadoRadius = radius;
}


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

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

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

- (void)dealloc {
    
}

@end
