






#import "AnyToast.h"
#import "DigitSongManager.h"


static UIColor *shapePinchOffNumericVideoColor = nil;
static UIColor *sixPoloExactColor = nil;
static UIFont *formActivate = nil;
static CGFloat oneDirtySumOldRadius = 6.0;
static UIEdgeInsets floatInsetEnclosingMembersRunBegin = {10, 16, 10, 16};

@interface AnyToast()
@property (nonatomic, strong) UILabel *dustSawLabel;
@property (nonatomic, strong) NSTimer *warpMayTimer;
@property (nonatomic, assign) MaximumRedMountedPickerMagnetic position;
@end

@implementation AnyToast


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


+ (void)show:(NSString *)message
    duration:(NSTimeInterval)duration
    position:(MaximumRedMountedPickerMagnetic)position
{
    
    dispatch_async(dispatch_get_main_queue(), ^{
        AnyToast *elder = [[AnyToast alloc] initPassMessage:message];
        elder.position = position;
        [elder unknownSoftnessCreditPlusPrevented];
        [elder cursorsHowItalicAlpineExcluded:duration];
    });
}

- (void)cursorsHowItalicAlpineExcluded:(NSTimeInterval)duration {
    UIWindow *window = [DigitSongManager.shared irregularHerWindow];
    [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 causePlayableItsManualSessionAnimation];
    
    
    if (duration > 0) {
        __weak typeof(self) weakSelf = self;
        self.warpMayTimer = [NSTimer scheduledTimerWithTimeInterval:duration repeats:YES block:^(NSTimer * _Nonnull solve) {
            [weakSelf dismiss];
        }];
    }
}

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


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

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


- (void)unknownSoftnessCreditPlusPrevented {
    UIView *container = self.dustSawLabel.superview;
    
    
    switch (self.position) {
        case ImageHexDiscountsArgumentsEqual: {
            [container.topAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.topAnchor
                                               constant:30].active = YES;
            break;
        }
        case WaistWhiteStorageBoxVitaminCenter: {
            [container.centerYAnchor constraintEqualToAnchor:self.centerYAnchor].active = YES;
            break;
        }
        case SecondaryEditorialArtArabicLoopDiastolic: {
            [container.bottomAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.bottomAnchor
                                                  constant:-30].active = YES;
            break;
        }
    }
    
    
    [container.centerXAnchor constraintEqualToAnchor:self.centerXAnchor].active = YES;
}


+ (void)formAudiencesGivenMutePitchEraColor:(UIColor *)color {
    shapePinchOffNumericVideoColor = color;
}

+ (void)iodineFivePoloColor:(UIColor *)color {
    sixPoloExactColor = color;
}

+ (void)abortPerformed:(UIFont *)font {
    formActivate = font;
}

+ (void)spouseCaptionNeutralReminderPassivelyRadius:(CGFloat)radius {
    oneDirtySumOldRadius = radius;
}


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

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

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

- (void)dealloc {
    
}

@end
