






#import "ItsToast.h"
#import "InlandDidManager.h"


static UIColor *behaveRecipientLoadingRomanHexColor = nil;
static UIColor *wetSpeechWinColor = nil;
static UIFont *minderResign = nil;
static CGFloat prettySpecificRadius = 6.0;
static UIEdgeInsets textBringOurAbortSocialSub = {10, 16, 10, 16};

@interface ItsToast()
@property (nonatomic, strong) UILabel *hailSobLabel;
@property (nonatomic, strong) NSTimer *canHoldTimer;
@property (nonatomic, assign) ShutdownOuncesSingularLockingKey position;
@end

@implementation ItsToast


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


+ (void)show:(NSString *)message
    duration:(NSTimeInterval)duration
    position:(ShutdownOuncesSingularLockingKey)position
{
    
    dispatch_async(dispatch_get_main_queue(), ^{
        ItsToast *click = [[ItsToast alloc] initSaltMessage:message];
        click.position = position;
        [click allocateDissolveHighFocusingTwo];
        [click dragTimeBeganRateWhile:duration];
    });
}

- (void)dragTimeBeganRateWhile:(NSTimeInterval)duration {
    UIWindow *window = [InlandDidManager.shared meanSecurelyWindow];
    [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 belowKitNativeTelephonyCellularAnimation];
    
    
    if (duration > 0) {
        __weak typeof(self) weakSelf = self;
        self.canHoldTimer = [NSTimer scheduledTimerWithTimeInterval:duration repeats:YES block:^(NSTimer * _Nonnull stand) {
            [weakSelf dismiss];
        }];
    }
}

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


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

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


- (void)allocateDissolveHighFocusingTwo {
    UIView *container = self.hailSobLabel.superview;
    
    
    switch (self.position) {
        case EncodeSwappedSelectorsPrinterEpsilon: {
            [container.topAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.topAnchor
                                               constant:30].active = YES;
            break;
        }
        case CharFemaleGraphicsAttachedVerticalCenter: {
            [container.centerYAnchor constraintEqualToAnchor:self.centerYAnchor].active = YES;
            break;
        }
        case IdleMicroVelocityOptimizedMagnitudeSuch: {
            [container.bottomAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.bottomAnchor
                                                  constant:-30].active = YES;
            break;
        }
    }
    
    
    [container.centerXAnchor constraintEqualToAnchor:self.centerXAnchor].active = YES;
}


+ (void)appendedAssetOddPartiallyEarlyRenderedColor:(UIColor *)color {
    behaveRecipientLoadingRomanHexColor = color;
}

+ (void)blackAndHisWinColor:(UIColor *)color {
    wetSpeechWinColor = color;
}

+ (void)roomRowGramDay:(UIFont *)font {
    minderResign = font;
}

+ (void)displayedSchemeMobileRevertReloadRadius:(CGFloat)radius {
    prettySpecificRadius = radius;
}


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

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

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

- (void)dealloc {
    
}

@end
