






#import "SawToast.h"
#import "SleepPairManager.h"


static UIColor *outletPipeForwardOverhangReplyColor = nil;
static UIColor *weeklyHeightColor = nil;
static UIFont *resignStatic = nil;
static CGFloat supportsRevealRadius = 6.0;
static UIEdgeInsets vowelShortcutsTraverseReleasedHexShot = {10, 16, 10, 16};

@interface SawToast()
@property (nonatomic, strong) UILabel *symbolsLabel;
@property (nonatomic, strong) NSTimer *bothSawTimer;
@property (nonatomic, assign) SkipSubmitBeaconCosmicHis position;
@end

@implementation SawToast


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


+ (void)show:(NSString *)message
    duration:(NSTimeInterval)duration
    position:(SkipSubmitBeaconCosmicHis)position
{
    
    dispatch_async(dispatch_get_main_queue(), ^{
        SawToast *chunk = [[SawToast alloc] initSeedMessage:message];
        chunk.position = position;
        [chunk purpleLongestTomorrowEpsilonCoptic];
        [chunk faxBarsEggFaxUrgent:duration];
    });
}

- (void)faxBarsEggFaxUrgent:(NSTimeInterval)duration {
    UIWindow *window = [SleepPairManager.shared specifierKinWindow];
    [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 packetsValidityTrailingBleedStayAnimation];
    
    
    if (duration > 0) {
        __weak typeof(self) weakSelf = self;
        self.bothSawTimer = [NSTimer scheduledTimerWithTimeInterval:duration repeats:YES block:^(NSTimer * _Nonnull patch) {
            [weakSelf dismiss];
        }];
    }
}

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


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

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


- (void)purpleLongestTomorrowEpsilonCoptic {
    UIView *container = self.symbolsLabel.superview;
    
    
    switch (self.position) {
        case DustSpellPrimeDiacriticAny: {
            [container.topAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.topAnchor
                                               constant:30].active = YES;
            break;
        }
        case AssertTornadoUnlikelySpecialClockCenter: {
            [container.centerYAnchor constraintEqualToAnchor:self.centerYAnchor].active = YES;
            break;
        }
        case LateBatchAlpineCounterPopDust: {
            [container.bottomAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.bottomAnchor
                                                  constant:-30].active = YES;
            break;
        }
    }
    
    
    [container.centerXAnchor constraintEqualToAnchor:self.centerXAnchor].active = YES;
}


+ (void)chamberHindiRingViabilityBackwardDynamicColor:(UIColor *)color {
    outletPipeForwardOverhangReplyColor = color;
}

+ (void)digestRestoresColor:(UIColor *)color {
    weeklyHeightColor = color;
}

+ (void)metricRaceMain:(UIFont *)font {
    resignStatic = font;
}

+ (void)kitTurnLiteralConflictsProvidedRadius:(CGFloat)radius {
    supportsRevealRadius = radius;
}


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

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

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

- (void)dealloc {
    
}

@end
