






#import "MidToast.h"
#import "MatchMenuManager.h"


static UIColor *heapForkIndexMotionReuseColor = nil;
static UIColor *decideRepeatColor = nil;
static UIFont *putFitUnique = nil;
static CGFloat talkBadBoldKeyRadius = 6.0;
static UIEdgeInsets protectedOverflowOverEditorsAuditYears = {10, 16, 10, 16};

@interface MidToast()
@property (nonatomic, strong) UILabel *encryptLabel;
@property (nonatomic, strong) NSTimer *kerningTimer;
@property (nonatomic, assign) RankedBreakingWetUsesSwitch position;
@end

@implementation MidToast


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


+ (void)show:(NSString *)message
    duration:(NSTimeInterval)duration
    position:(RankedBreakingWetUsesSwitch)position
{
    
    dispatch_async(dispatch_get_main_queue(), ^{
        MidToast *arrow = [[MidToast alloc] initFeedMessage:message];
        arrow.position = position;
        [arrow followerBuilderEligibleArmenianAnother];
        [arrow ticketsFloatingStereoBrotherLaw:duration];
    });
}

- (void)ticketsFloatingStereoBrotherLaw:(NSTimeInterval)duration {
    UIWindow *window = [MatchMenuManager.shared teacherDepthWindow];
    [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 encryptReactorRenewRevertTriangleAnimation];
    
    
    if (duration > 0) {
        __weak typeof(self) weakSelf = self;
        self.kerningTimer = [NSTimer scheduledTimerWithTimeInterval:duration repeats:YES block:^(NSTimer * _Nonnull stamp) {
            [weakSelf dismiss];
        }];
    }
}

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


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

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


- (void)followerBuilderEligibleArmenianAnother {
    UIView *container = self.encryptLabel.superview;
    
    
    switch (self.position) {
        case PhysicalLanguagesObscuresWidthAcute: {
            [container.topAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.topAnchor
                                               constant:30].active = YES;
            break;
        }
        case ReductionLooperFlashSyntaxFileCenter: {
            [container.centerYAnchor constraintEqualToAnchor:self.centerYAnchor].active = YES;
            break;
        }
        case ProgressDivideResizingCarClustersJoule: {
            [container.bottomAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.bottomAnchor
                                                  constant:-30].active = YES;
            break;
        }
    }
    
    
    [container.centerXAnchor constraintEqualToAnchor:self.centerXAnchor].active = YES;
}


+ (void)balticFloatPastDescendedSinUndoColor:(UIColor *)color {
    heapForkIndexMotionReuseColor = color;
}

+ (void)birthPreservesColor:(UIColor *)color {
    decideRepeatColor = color;
}

+ (void)infinitePaddle:(UIFont *)font {
    putFitUnique = font;
}

+ (void)hyphenFirstEditorPersianHoursRadius:(CGFloat)radius {
    talkBadBoldKeyRadius = radius;
}


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

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

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

- (void)dealloc {
    
}

@end
