






#import "SubToast.h"
#import "RelevanceManager.h"


static UIColor *smallestTaskUseParseCyrillicColor = nil;
static UIColor *numberKeyHowColor = nil;
static UIFont *supplyNormal = nil;
static CGFloat midLogoBinLockRadius = 6.0;
static UIEdgeInsets noteReasonPositionRematchBurstPing = {10, 16, 10, 16};

@interface SubToast()
@property (nonatomic, strong) UILabel *scannerLabel;
@property (nonatomic, strong) NSTimer *pickGetTimer;
@property (nonatomic, assign) MeterAnswerFaxBuddyYard position;
@end

@implementation SubToast


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


+ (void)show:(NSString *)message
    duration:(NSTimeInterval)duration
    position:(MeterAnswerFaxBuddyYard)position
{
    
    dispatch_async(dispatch_get_main_queue(), ^{
        SubToast *tight = [[SubToast alloc] initWarpMessage:message];
        tight.position = position;
        [tight locationRealRetLiterSindhi];
        [tight tryLocationsSharpnessObservingReached:duration];
    });
}

- (void)tryLocationsSharpnessObservingReached:(NSTimeInterval)duration {
    UIWindow *window = [RelevanceManager.shared ropeAnimatorWindow];
    [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 cleanupAfterInsertSpaceRestoredAnimation];
    
    
    if (duration > 0) {
        __weak typeof(self) weakSelf = self;
        self.pickGetTimer = [NSTimer scheduledTimerWithTimeInterval:duration repeats:YES block:^(NSTimer * _Nonnull segue) {
            [weakSelf dismiss];
        }];
    }
}

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


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

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


- (void)locationRealRetLiterSindhi {
    UIView *container = self.scannerLabel.superview;
    
    
    switch (self.position) {
        case WeightCloudEncodingMeasuredDaily: {
            [container.topAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.topAnchor
                                               constant:30].active = YES;
            break;
        }
        case SubDisableGreekConvertSpeakCenter: {
            [container.centerYAnchor constraintEqualToAnchor:self.centerYAnchor].active = YES;
            break;
        }
        case UpsideGreenTransmitSuffixFocalUrgency: {
            [container.bottomAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.bottomAnchor
                                                  constant:-30].active = YES;
            break;
        }
    }
    
    
    [container.centerXAnchor constraintEqualToAnchor:self.centerXAnchor].active = YES;
}


+ (void)zoomingDefinesInnerLocaleLettersFlushedColor:(UIColor *)color {
    smallestTaskUseParseCyrillicColor = color;
}

+ (void)usabilityInuitColor:(UIColor *)color {
    numberKeyHowColor = color;
}

+ (void)sinFixHalfBeen:(UIFont *)font {
    supplyNormal = font;
}

+ (void)usabilityApplyChainShrinkSafeRadius:(CGFloat)radius {
    midLogoBinLockRadius = radius;
}


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

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

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

- (void)dealloc {
    
}

@end
