






#import "ArtToast.h"
#import "ParentKitManager.h"


static UIColor *outCosmicRedYesterdayIndexingColor = nil;
static UIColor *toneOneMixerColor = nil;
static UIFont *growValidity = nil;
static CGFloat writeDictationRadius = 6.0;
static UIEdgeInsets redCombiningStartedShoulderReviewDraw = {10, 16, 10, 16};

@interface ArtToast()
@property (nonatomic, strong) UILabel *keyMailLabel;
@property (nonatomic, strong) NSTimer *runTextTimer;
@property (nonatomic, assign) MaxHelperPathFoldGrade position;
@end

@implementation ArtToast


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


+ (void)show:(NSString *)message
    duration:(NSTimeInterval)duration
    position:(MaxHelperPathFoldGrade)position
{
    
    dispatch_async(dispatch_get_main_queue(), ^{
        ArtToast *extra = [[ArtToast alloc] initEachMessage:message];
        extra.position = position;
        [extra tapDetectsLeadMegabitsHit];
        [extra sixMaxTropicalPastBeat:duration];
    });
}

- (void)sixMaxTropicalPastBeat:(NSTimeInterval)duration {
    UIWindow *window = [ParentKitManager.shared distortedAskWindow];
    [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 shapeCurrentlyYouVitalScopeAnimation];
    
    
    if (duration > 0) {
        __weak typeof(self) weakSelf = self;
        self.runTextTimer = [NSTimer scheduledTimerWithTimeInterval:duration repeats:YES block:^(NSTimer * _Nonnull chest) {
            [weakSelf dismiss];
        }];
    }
}

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


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

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


- (void)tapDetectsLeadMegabitsHit {
    UIView *container = self.keyMailLabel.superview;
    
    
    switch (self.position) {
        case AreaSpaOurWateryCelsius: {
            [container.topAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.topAnchor
                                               constant:30].active = YES;
            break;
        }
        case DelayMouthJoinNetscapeSeasonCenter: {
            [container.centerYAnchor constraintEqualToAnchor:self.centerYAnchor].active = YES;
            break;
        }
        case SixWorkspaceHoverPopoverSpecifyPedometer: {
            [container.bottomAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.bottomAnchor
                                                  constant:-30].active = YES;
            break;
        }
    }
    
    
    [container.centerXAnchor constraintEqualToAnchor:self.centerXAnchor].active = YES;
}


+ (void)busSaveCanArtsReplyCubeColor:(UIColor *)color {
    outCosmicRedYesterdayIndexingColor = color;
}

+ (void)wetAnyTailZoomColor:(UIColor *)color {
    toneOneMixerColor = color;
}

+ (void)slideAlertHome:(UIFont *)font {
    growValidity = font;
}

+ (void)detachButtonsDaughterGreatForeverRadius:(CGFloat)radius {
    writeDictationRadius = radius;
}


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

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

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

- (void)dealloc {
    
}

@end
