






#import "ButToast.h"
#import "FunnelArmManager.h"


static UIColor *aliveMoireOperationMoveCutterColor = nil;
static UIColor *receivingKinColor = nil;
static UIFont *outPeopleTen = nil;
static CGFloat changeFadeSkipRadius = 6.0;
static UIEdgeInsets clampingHisCoastSentinelInventoryEither = {10, 16, 10, 16};

@interface ButToast()
@property (nonatomic, strong) UILabel *tradFaxLabel;
@property (nonatomic, strong) NSTimer *licenseTimer;
@property (nonatomic, assign) TransientLaotianListenersPrintedKit position;
@end

@implementation ButToast


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


+ (void)show:(NSString *)message
    duration:(NSTimeInterval)duration
    position:(TransientLaotianListenersPrintedKit)position
{
    
    dispatch_async(dispatch_get_main_queue(), ^{
        ButToast *radio = [[ButToast alloc] initWaitMessage:message];
        radio.position = position;
        [radio oneFocusingRatioProvinceLigatures];
        [radio persistFirstUsedFavoritesViability:duration];
    });
}

- (void)persistFirstUsedFavoritesViability:(NSTimeInterval)duration {
    UIWindow *window = [FunnelArmManager.shared bedShiftMoveWindow];
    [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 busTensionLemmaCaffeineLappishAnimation];
    
    
    if (duration > 0) {
        __weak typeof(self) weakSelf = self;
        self.licenseTimer = [NSTimer scheduledTimerWithTimeInterval:duration repeats:YES block:^(NSTimer * _Nonnull stale) {
            [weakSelf dismiss];
        }];
    }
}

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


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

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


- (void)oneFocusingRatioProvinceLigatures {
    UIView *container = self.tradFaxLabel.superview;
    
    
    switch (self.position) {
        case PrepareAirBaseNecessaryPopover: {
            [container.topAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.topAnchor
                                               constant:30].active = YES;
            break;
        }
        case SmileHeadphoneAppearFivePageCenter: {
            [container.centerYAnchor constraintEqualToAnchor:self.centerYAnchor].active = YES;
            break;
        }
        case FormIndexStepchildReturnedConditionFocusing: {
            [container.bottomAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.bottomAnchor
                                                  constant:-30].active = YES;
            break;
        }
    }
    
    
    [container.centerXAnchor constraintEqualToAnchor:self.centerXAnchor].active = YES;
}


+ (void)providedAccordingDarkerSlabCadenceBitsColor:(UIColor *)color {
    aliveMoireOperationMoveCutterColor = color;
}

+ (void)segueInterlaceColor:(UIColor *)color {
    receivingKinColor = color;
}

+ (void)datumSinAgeKey:(UIFont *)font {
    outPeopleTen = font;
}

+ (void)hundredContainSilencedFastSmartRadius:(CGFloat)radius {
    changeFadeSkipRadius = radius;
}


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

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

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

- (void)dealloc {
    
}

@end
