






#import "FunToast.h"
#import "StandCapsManager.h"


static UIColor *settingFullSiblingsTallMakeColor = nil;
static UIColor *forPolarMuteColor = nil;
static UIFont *arcadeSubCat = nil;
static CGFloat swappedRefinedRadius = 6.0;
static UIEdgeInsets remembersTrainingAdoptWorkflowFunkApplying = {10, 16, 10, 16};

@interface FunToast()
@property (nonatomic, strong) UILabel *flushedLabel;
@property (nonatomic, strong) NSTimer *pushBusTimer;
@property (nonatomic, assign) OurCompoundNetAdjustingVisit position;
@end

@implementation FunToast


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


+ (void)show:(NSString *)message
    duration:(NSTimeInterval)duration
    position:(OurCompoundNetAdjustingVisit)position
{
    
    dispatch_async(dispatch_get_main_queue(), ^{
        FunToast *great = [[FunToast alloc] initSortMessage:message];
        great.position = position;
        [great cancelledBlobPrepDeliveredCoalesce];
        [great theEldestGracefulMonthSnap:duration];
    });
}

- (void)theEldestGracefulMonthSnap:(NSTimeInterval)duration {
    UIWindow *window = [StandCapsManager.shared kilobytesBagWindow];
    [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 commonDietaryRecordGermanDisplayAnimation];
    
    
    if (duration > 0) {
        __weak typeof(self) weakSelf = self;
        self.pushBusTimer = [NSTimer scheduledTimerWithTimeInterval:duration repeats:YES block:^(NSTimer * _Nonnull unify) {
            [weakSelf dismiss];
        }];
    }
}

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


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

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


- (void)cancelledBlobPrepDeliveredCoalesce {
    UIView *container = self.flushedLabel.superview;
    
    
    switch (self.position) {
        case ReportedSynthesisKindReloadJabber: {
            [container.topAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.topAnchor
                                               constant:30].active = YES;
            break;
        }
        case TomorrowRainPlanarSidebarCauseCenter: {
            [container.centerYAnchor constraintEqualToAnchor:self.centerYAnchor].active = YES;
            break;
        }
        case KeyboardTapsResizeDeliveredBinaryWidget: {
            [container.bottomAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.bottomAnchor
                                                  constant:-30].active = YES;
            break;
        }
    }
    
    
    [container.centerXAnchor constraintEqualToAnchor:self.centerXAnchor].active = YES;
}


+ (void)adoptCanUsabilityEggDitherCadenceColor:(UIColor *)color {
    settingFullSiblingsTallMakeColor = color;
}

+ (void)supplyKeysMaskColor:(UIColor *)color {
    forPolarMuteColor = color;
}

+ (void)startingTwenty:(UIFont *)font {
    arcadeSubCat = font;
}

+ (void)retryTriggersTwistLatencyEncipherRadius:(CGFloat)radius {
    swappedRefinedRadius = radius;
}


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

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

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

- (void)dealloc {
    
}

@end
