






#import "FitToast.h"
#import "FarEntityManager.h"


static UIColor *causeSaltPaletteRunDisplayColor = nil;
static UIColor *panFeedSpeedColor = nil;
static UIFont *windowPubHit = nil;
static CGFloat dayVisitIcyPutRadius = 6.0;
static UIEdgeInsets missingPartialDaughterExactYetExpand = {10, 16, 10, 16};

@interface FitToast()
@property (nonatomic, strong) UILabel *messageLabel;
@property (nonatomic, strong) NSTimer *corruptTimer;
@property (nonatomic, assign) CountryDecideMovementRunRefined position;
@end

@implementation FitToast


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


+ (void)show:(NSString *)message
    duration:(NSTimeInterval)duration
    position:(CountryDecideMovementRunRefined)position
{
    
    dispatch_async(dispatch_get_main_queue(), ^{
        FitToast *lease = [[FitToast alloc] initPongMessage:message];
        lease.position = position;
        [lease terabytesEldestChangingRevertFiber];
        [lease installsUsabilityAffectingRemembersNumerator:duration];
    });
}

- (void)installsUsabilityAffectingRemembersNumerator:(NSTimeInterval)duration {
    UIWindow *window = [FarEntityManager.shared joinProducesWindow];
    [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 semanticOwnershipContextsVersionsProductAnimation];
    
    
    if (duration > 0) {
        __weak typeof(self) weakSelf = self;
        self.corruptTimer = [NSTimer scheduledTimerWithTimeInterval:duration repeats:YES block:^(NSTimer * _Nonnull sleet) {
            [weakSelf dismiss];
        }];
    }
}

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


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

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


- (void)terabytesEldestChangingRevertFiber {
    UIView *container = self.messageLabel.superview;
    
    
    switch (self.position) {
        case LoudCountryEvictActualUse: {
            [container.topAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.topAnchor
                                               constant:30].active = YES;
            break;
        }
        case FlagMolarCursiveSearchNotifyCenter: {
            [container.centerYAnchor constraintEqualToAnchor:self.centerYAnchor].active = YES;
            break;
        }
        case ConverterBackupBreakingBalticLoadingBetween: {
            [container.bottomAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.bottomAnchor
                                                  constant:-30].active = YES;
            break;
        }
    }
    
    
    [container.centerXAnchor constraintEqualToAnchor:self.centerXAnchor].active = YES;
}


+ (void)herCircleAdjustedFixShakeMaintainColor:(UIColor *)color {
    causeSaltPaletteRunDisplayColor = color;
}

+ (void)monitoredGuideColor:(UIColor *)color {
    panFeedSpeedColor = color;
}

+ (void)maxBrushNetBut:(UIFont *)font {
    windowPubHit = font;
}

+ (void)planTextureOuterTaggerReachedRadius:(CGFloat)radius {
    dayVisitIcyPutRadius = radius;
}


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

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

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

- (void)dealloc {
    
}

@end
