






#import "FixToast.h"
#import "SeparatedManager.h"


static UIColor *rhythmOperatingNewsstandCutSamplesColor = nil;
static UIColor *fairStandPopColor = nil;
static UIFont *unlockNowRun = nil;
static CGFloat stopStereoStepRadius = 6.0;
static UIEdgeInsets sixTamilGeneratesLaotianTopGeorgian = {10, 16, 10, 16};

@interface FixToast()
@property (nonatomic, strong) UILabel *offFunkLabel;
@property (nonatomic, strong) NSTimer *failPubTimer;
@property (nonatomic, assign) SummariesLossyYetPutSon position;
@end

@implementation FixToast


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


+ (void)show:(NSString *)message
    duration:(NSTimeInterval)duration
    position:(SummariesLossyYetPutSon)position
{
    
    dispatch_async(dispatch_get_main_queue(), ^{
        FixToast *extra = [[FixToast alloc] initBlobMessage:message];
        extra.position = position;
        [extra existentBinaryMinuteEchoSub];
        [extra overlayPartiallyToneMusicalThumbnail:duration];
    });
}

- (void)overlayPartiallyToneMusicalThumbnail:(NSTimeInterval)duration {
    UIWindow *window = [SeparatedManager.shared nordicBecomeWindow];
    [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 ditheredBasicParsingAboutNotifyAnimation];
    
    
    if (duration > 0) {
        __weak typeof(self) weakSelf = self;
        self.failPubTimer = [NSTimer scheduledTimerWithTimeInterval:duration repeats:YES block:^(NSTimer * _Nonnull slide) {
            [weakSelf dismiss];
        }];
    }
}

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


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

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


- (void)existentBinaryMinuteEchoSub {
    UIView *container = self.offFunkLabel.superview;
    
    
    switch (self.position) {
        case TensionLemmaCocoaUnableMay: {
            [container.topAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.topAnchor
                                               constant:30].active = YES;
            break;
        }
        case DeviceAuthorsConverterSafetyAffectingCenter: {
            [container.centerYAnchor constraintEqualToAnchor:self.centerYAnchor].active = YES;
            break;
        }
        case OceanAssameseAlertDisplayMayOrdering: {
            [container.bottomAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.bottomAnchor
                                                  constant:-30].active = YES;
            break;
        }
    }
    
    
    [container.centerXAnchor constraintEqualToAnchor:self.centerXAnchor].active = YES;
}


+ (void)brushFoodEggDebuggingSheTeamColor:(UIColor *)color {
    rhythmOperatingNewsstandCutSamplesColor = color;
}

+ (void)hexWaxEnterMixColor:(UIColor *)color {
    fairStandPopColor = color;
}

+ (void)titleDecompose:(UIFont *)font {
    unlockNowRun = font;
}

+ (void)callbackBufferingBirthFastLegacyRadius:(CGFloat)radius {
    stopStereoStepRadius = radius;
}


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

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

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

- (void)dealloc {
    
}

@end
