






#import "WasToast.h"
#import "KeysVoiceManager.h"


static UIColor *sinDetectionStormFitGestureColor = nil;
static UIColor *outHitOutletColor = nil;
static UIFont *floatingFeat = nil;
static CGFloat pivotWeekDenseRadius = 6.0;
static UIEdgeInsets exclusiveSwahiliLegacyManualFactorPeak = {10, 16, 10, 16};

@interface WasToast()
@property (nonatomic, strong) UILabel *areQuitLabel;
@property (nonatomic, strong) NSTimer *nowSongTimer;
@property (nonatomic, assign) NothingEnumerateArtMostlyPen position;
@end

@implementation WasToast


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


+ (void)show:(NSString *)message
    duration:(NSTimeInterval)duration
    position:(NothingEnumerateArtMostlyPen)position
{
    
    dispatch_async(dispatch_get_main_queue(), ^{
        WasToast *slant = [[WasToast alloc] initThatMessage:message];
        slant.position = position;
        [slant meanSymbolMusicalSectionsViolation];
        [slant discardHoverWaySplatCollision:duration];
    });
}

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

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


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

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


- (void)meanSymbolMusicalSectionsViolation {
    UIView *container = self.areQuitLabel.superview;
    
    
    switch (self.position) {
        case EarErrorBuiltTrapCaution: {
            [container.topAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.topAnchor
                                               constant:30].active = YES;
            break;
        }
        case ChromiumSpecialOutDesignAirCenter: {
            [container.centerYAnchor constraintEqualToAnchor:self.centerYAnchor].active = YES;
            break;
        }
        case FlatnessEphemeralRealIdleDefaultsAlpine: {
            [container.bottomAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.bottomAnchor
                                                  constant:-30].active = YES;
            break;
        }
    }
    
    
    [container.centerXAnchor constraintEqualToAnchor:self.centerXAnchor].active = YES;
}


+ (void)denseHexRespondSceneLawThresholdColor:(UIColor *)color {
    sinDetectionStormFitGestureColor = color;
}

+ (void)rawLowEarVisitColor:(UIColor *)color {
    outHitOutletColor = color;
}

+ (void)leapMidOptNine:(UIFont *)font {
    floatingFeat = font;
}

+ (void)sunLeakyAxialAccuracyItalicRadius:(CGFloat)radius {
    pivotWeekDenseRadius = radius;
}


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

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

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

- (void)dealloc {
    
}

@end
