






#import "MidToast.h"
#import "WasFillerManager.h"


static UIColor *sphereMomentDownloadWireFreeColor = nil;
static UIColor *subDarkerHisColor = nil;
static UIFont *bagMinArabic = nil;
static CGFloat dimensionSoundRadius = 6.0;
static UIEdgeInsets lockingLandscapeSunShortToneExtent = {10, 16, 10, 16};

@interface MidToast()
@property (nonatomic, strong) UILabel *zipLongLabel;
@property (nonatomic, strong) NSTimer *youCharTimer;
@property (nonatomic, assign) PhotosLegibleInsulinClusterFit position;
@end

@implementation MidToast


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


+ (void)show:(NSString *)message
    duration:(NSTimeInterval)duration
    position:(PhotosLegibleInsulinClusterFit)position
{
    
    dispatch_async(dispatch_get_main_queue(), ^{
        MidToast *serif = [[MidToast alloc] initHintMessage:message];
        serif.position = position;
        [serif quantityKilogramsGroupingHerBirth];
        [serif croppingHailScrolledEggAlign:duration];
    });
}

- (void)croppingHailScrolledEggAlign:(NSTimeInterval)duration {
    UIWindow *window = [WasFillerManager.shared delaySubPickWindow];
    [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 sizeLaunchRebusClickedTheAnimation];
    
    
    if (duration > 0) {
        __weak typeof(self) weakSelf = self;
        self.youCharTimer = [NSTimer scheduledTimerWithTimeInterval:duration repeats:YES block:^(NSTimer * _Nonnull plate) {
            [weakSelf dismiss];
        }];
    }
}

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


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

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


- (void)quantityKilogramsGroupingHerBirth {
    UIView *container = self.zipLongLabel.superview;
    
    
    switch (self.position) {
        case TriggeredBitmapWeightedPaceHundred: {
            [container.topAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.topAnchor
                                               constant:30].active = YES;
            break;
        }
        case PrintableClientDecipherSpaEffectCenter: {
            [container.centerYAnchor constraintEqualToAnchor:self.centerYAnchor].active = YES;
            break;
        }
        case BagDirectRouteMouseInterWon: {
            [container.bottomAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.bottomAnchor
                                                  constant:-30].active = YES;
            break;
        }
    }
    
    
    [container.centerXAnchor constraintEqualToAnchor:self.centerXAnchor].active = YES;
}


+ (void)logTheOutDownMinArchiveColor:(UIColor *)color {
    sphereMomentDownloadWireFreeColor = color;
}

+ (void)rowNetStarLostColor:(UIColor *)color {
    subDarkerHisColor = color;
}

+ (void)expensiveElder:(UIFont *)font {
    bagMinArabic = font;
}

+ (void)desiredSignalingDueVerifyColumnRadius:(CGFloat)radius {
    dimensionSoundRadius = radius;
}


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

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

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

- (void)dealloc {
    
}

@end
