






#import "SawToast.h"
#import "BeaconAskManager.h"


static UIColor *guideWrapperCenterNumeratorForkColor = nil;
static UIColor *optionScriptColor = nil;
static UIFont *colorSafeTap = nil;
static CGFloat barPinPutRouteRadius = 6.0;
static UIEdgeInsets purposePitchAccessingLongMixLoose = {10, 16, 10, 16};

@interface SawToast()
@property (nonatomic, strong) UILabel *blobBedLabel;
@property (nonatomic, strong) NSTimer *flipSonTimer;
@property (nonatomic, assign) MidBigDatabasesRowsSummary position;
@end

@implementation SawToast


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


+ (void)show:(NSString *)message
    duration:(NSTimeInterval)duration
    position:(MidBigDatabasesRowsSummary)position
{
    
    dispatch_async(dispatch_get_main_queue(), ^{
        SawToast *fully = [[SawToast alloc] initJustMessage:message];
        fully.position = position;
        [fully unwindingRemovableNativeIrishObsolete];
        [fully scaleSheExtraAscentBadminton:duration];
    });
}

- (void)scaleSheExtraAscentBadminton:(NSTimeInterval)duration {
    UIWindow *window = [BeaconAskManager.shared detachCreditWindow];
    [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 stripRespondWordCalciumGenderAnimation];
    
    
    if (duration > 0) {
        __weak typeof(self) weakSelf = self;
        self.flipSonTimer = [NSTimer scheduledTimerWithTimeInterval:duration repeats:YES block:^(NSTimer * _Nonnull birth) {
            [weakSelf dismiss];
        }];
    }
}

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


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

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


- (void)unwindingRemovableNativeIrishObsolete {
    UIView *container = self.blobBedLabel.superview;
    
    
    switch (self.position) {
        case StartupBorderWarpPotassiumTamil: {
            [container.topAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.topAnchor
                                               constant:30].active = YES;
            break;
        }
        case ActionsAdjustReturnedFarRadiansCenter: {
            [container.centerYAnchor constraintEqualToAnchor:self.centerYAnchor].active = YES;
            break;
        }
        case EstimatedBusMetricBandPlayableCalling: {
            [container.bottomAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.bottomAnchor
                                                  constant:-30].active = YES;
            break;
        }
    }
    
    
    [container.centerXAnchor constraintEqualToAnchor:self.centerXAnchor].active = YES;
}


+ (void)handoffTelephoneImportantPeerPostalWayColor:(UIColor *)color {
    guideWrapperCenterNumeratorForkColor = color;
}

+ (void)invokeDeclinedColor:(UIColor *)color {
    optionScriptColor = color;
}

+ (void)maxVideoBoxBig:(UIFont *)font {
    colorSafeTap = font;
}

+ (void)coastCascadeCompoundOceanAnswerRadius:(CGFloat)radius {
    barPinPutRouteRadius = radius;
}


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

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

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

- (void)dealloc {
    
}

@end
