






#import "PubToast.h"
#import "FormThirdManager.h"


static UIColor *correctedPermuteNorthSmoothedCupColor = nil;
static UIColor *wasNoteUnderColor = nil;
static UIFont *outerDayStar = nil;
static CGFloat waistSobEggBedRadius = 6.0;
static UIEdgeInsets rawAudiencesAmbiguousNextSecurityDithered = {10, 16, 10, 16};

@interface PubToast()
@property (nonatomic, strong) UILabel *packHisLabel;
@property (nonatomic, strong) NSTimer *audibleTimer;
@property (nonatomic, assign) ProvidedHungarianReadComplexCanceling position;
@end

@implementation PubToast


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


+ (void)show:(NSString *)message
    duration:(NSTimeInterval)duration
    position:(ProvidedHungarianReadComplexCanceling)position
{
    
    dispatch_async(dispatch_get_main_queue(), ^{
        PubToast *rebus = [[PubToast alloc] initTiedMessage:message];
        rebus.position = position;
        [rebus providingTakeUnitChineseResolved];
        [rebus safeMusicGolfArgumentsScroll:duration];
    });
}

- (void)safeMusicGolfArgumentsScroll:(NSTimeInterval)duration {
    UIWindow *window = [FormThirdManager.shared partlyVisualWindow];
    [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 switchOrderedEntitledPowerExpandingAnimation];
    
    
    if (duration > 0) {
        __weak typeof(self) weakSelf = self;
        self.audibleTimer = [NSTimer scheduledTimerWithTimeInterval:duration repeats:YES block:^(NSTimer * _Nonnull audio) {
            [weakSelf dismiss];
        }];
    }
}

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


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

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


- (void)providingTakeUnitChineseResolved {
    UIView *container = self.packHisLabel.superview;
    
    
    switch (self.position) {
        case DuplicateDismissalSidebarChainOnly: {
            [container.topAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.topAnchor
                                               constant:30].active = YES;
            break;
        }
        case PositionsPhoneParsecsArrayDescenderCenter: {
            [container.centerYAnchor constraintEqualToAnchor:self.centerYAnchor].active = YES;
            break;
        }
        case EastBrowseTraveledEldestBracketIntersect: {
            [container.bottomAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.bottomAnchor
                                                  constant:-30].active = YES;
            break;
        }
    }
    
    
    [container.centerXAnchor constraintEqualToAnchor:self.centerXAnchor].active = YES;
}


+ (void)policyCriteriaEnablingHistoryEncryptManagersColor:(UIColor *)color {
    correctedPermuteNorthSmoothedCupColor = color;
}

+ (void)hasDoneYouFoodColor:(UIColor *)color {
    wasNoteUnderColor = color;
}

+ (void)headerNameWith:(UIFont *)font {
    outerDayStar = font;
}

+ (void)learnProblemRankRatioSeedRadius:(CGFloat)radius {
    waistSobEggBedRadius = radius;
}


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

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

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

- (void)dealloc {
    
}

@end
