






#import "LowAlertView.h"
#import "RuleListCut.h"
#import "PopParserManager.h"
#import "Masonry.h"

#define fourJob(our) __weak typeof(our) weak##our = our;
#define maskLocal(our) __strong typeof(our) our = weak##our;

@interface LowAlertView()

@property (nonatomic, strong) UIView *wetNotBedColorView;
@property (nonatomic, copy) JobRetryPartnerPassivelyFloaterParagraph completion;
@property (nonatomic, strong) UIStackView *deepFixMovieView;

@end

@implementation LowAlertView

- (void)dealloc {
    
}

- (instancetype)initWithFrame:(CGRect)frame
                          title:(NSString *)title
                        message:(NSString *)message
                   tryGetAmount:(NSArray<NSString *> *)tryGetAmount
                     completion:(JobRetryPartnerPassivelyFloaterParagraph)completion {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
        self.completion = completion;
        
        
        self.wetNotBedColorView = [[UIView alloc] init];
        self.wetNotBedColorView.backgroundColor = [RuleListCut slopeLockColor];
        self.wetNotBedColorView.layer.cornerRadius = RuleListCut.coloredDraft.malteseClamp;
        self.wetNotBedColorView.clipsToBounds = YES;
        self.wetNotBedColorView.translatesAutoresizingMaskIntoConstraints = NO;
        [self addSubview:self.wetNotBedColorView];
        
        
        [NSLayoutConstraint activateConstraints:@[
            [self.wetNotBedColorView.centerXAnchor constraintEqualToAnchor:self.centerXAnchor],
            [self.wetNotBedColorView.centerYAnchor constraintEqualToAnchor:self.centerYAnchor],
            [self.wetNotBedColorView.widthAnchor constraintEqualToConstant:270]
        ]];
        
        
        UIView *wetMolarView = nil;
        CGFloat cloudyItalianFitNearNeutral = 20;
        
        
        if (title.length > 0) {
            UILabel *titleLabel = [[UILabel alloc] init];
            titleLabel.text = title;
            titleLabel.textColor = UIColor.whiteColor;
            titleLabel.font = [UIFont boldSystemFontOfSize:18];
            titleLabel.textAlignment = NSTextAlignmentCenter;
            titleLabel.numberOfLines = 0;
            titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
            [self.wetNotBedColorView addSubview:titleLabel];
            
            [NSLayoutConstraint activateConstraints:@[
                [titleLabel.topAnchor constraintEqualToAnchor:self.wetNotBedColorView.topAnchor constant:cloudyItalianFitNearNeutral],
                [titleLabel.leadingAnchor constraintEqualToAnchor:self.wetNotBedColorView.leadingAnchor constant:16],
                [titleLabel.trailingAnchor constraintEqualToAnchor:self.wetNotBedColorView.trailingAnchor constant:-16]
            ]];
            
            wetMolarView = titleLabel;
        }
        
        
        if (message.length > 0) {
            UILabel *hitSuchLabel = [[UILabel alloc] init];
            hitSuchLabel.text = message;
            hitSuchLabel.textColor = UIColor.whiteColor;
            hitSuchLabel.font = [UIFont systemFontOfSize:15];
            hitSuchLabel.textAlignment = NSTextAlignmentCenter;
            hitSuchLabel.numberOfLines = 0;
            hitSuchLabel.translatesAutoresizingMaskIntoConstraints = NO;
            [self.wetNotBedColorView addSubview:hitSuchLabel];
            
            NSLayoutYAxisAnchor *topAnchor = wetMolarView ? wetMolarView.bottomAnchor : self.wetNotBedColorView.topAnchor;
            CGFloat endLowPass = wetMolarView ? 10 : cloudyItalianFitNearNeutral;
            [NSLayoutConstraint activateConstraints:@[
                [hitSuchLabel.topAnchor constraintEqualToAnchor:topAnchor constant:endLowPass],
                [hitSuchLabel.leadingAnchor constraintEqualToAnchor:self.wetNotBedColorView.leadingAnchor constant:16],
                [hitSuchLabel.trailingAnchor constraintEqualToAnchor:self.wetNotBedColorView.trailingAnchor constant:-16]
            ]];
            wetMolarView = hitSuchLabel;
        }
        
        
        self.deepFixMovieView = [[UIStackView alloc] init];
        self.deepFixMovieView.axis = UILayoutConstraintAxisVertical;
        self.deepFixMovieView.spacing = 1;  
        self.deepFixMovieView.distribution = UIStackViewDistributionFillEqually;
        self.deepFixMovieView.translatesAutoresizingMaskIntoConstraints = NO;
        [self.wetNotBedColorView addSubview:self.deepFixMovieView];
        
        
        NSLayoutYAxisAnchor *lighterCentersBuffersSlowStepchild = wetMolarView ? wetMolarView.bottomAnchor : self.wetNotBedColorView.topAnchor;
        CGFloat scriptsHundredsRenewedStrengthPromotion = wetMolarView ? cloudyItalianFitNearNeutral : cloudyItalianFitNearNeutral;
        
        [NSLayoutConstraint activateConstraints:@[
            [self.deepFixMovieView.topAnchor constraintEqualToAnchor:lighterCentersBuffersSlowStepchild constant:scriptsHundredsRenewedStrengthPromotion],
            [self.deepFixMovieView.leadingAnchor constraintEqualToAnchor:self.wetNotBedColorView.leadingAnchor],
            [self.deepFixMovieView.trailingAnchor constraintEqualToAnchor:self.wetNotBedColorView.trailingAnchor],
            [self.deepFixMovieView.bottomAnchor constraintEqualToAnchor:self.wetNotBedColorView.bottomAnchor]
        ]];
        
        
       
       if (tryGetAmount.count == 2) {
           
           self.deepFixMovieView = [[UIStackView alloc] init];
           self.deepFixMovieView.axis = UILayoutConstraintAxisHorizontal;
           self.deepFixMovieView.distribution = UIStackViewDistributionFillEqually;
           self.deepFixMovieView.spacing = 1;  
           self.deepFixMovieView.translatesAutoresizingMaskIntoConstraints = NO;
           [self.wetNotBedColorView addSubview:self.deepFixMovieView];
           
           NSLayoutYAxisAnchor *lighterCentersBuffersSlowStepchild = wetMolarView ? wetMolarView.bottomAnchor : self.wetNotBedColorView.topAnchor;
           [NSLayoutConstraint activateConstraints:@[
               [self.deepFixMovieView.topAnchor constraintEqualToAnchor:lighterCentersBuffersSlowStepchild constant:cloudyItalianFitNearNeutral],
               [self.deepFixMovieView.leadingAnchor constraintEqualToAnchor:self.wetNotBedColorView.leadingAnchor],
               [self.deepFixMovieView.trailingAnchor constraintEqualToAnchor:self.wetNotBedColorView.trailingAnchor],
               [self.deepFixMovieView.bottomAnchor constraintEqualToAnchor:self.wetNotBedColorView.bottomAnchor]
           ]];
           
           
           for (NSInteger i = 0; i < tryGetAmount.count; i++) {
               NSString *mutation = tryGetAmount[i];
               UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
               [button setTitle:mutation forState:UIControlStateNormal];
               button.titleLabel.font = [UIFont systemFontOfSize:17];
               [button setTitleColor:[RuleListCut slopeLockColor] forState:UIControlStateNormal];
               [button setTitleColor:UIColor.lightGrayColor forState:UIControlStateHighlighted];
               button.backgroundColor = [UIColor whiteColor];
               button.tag = i;
               [button addTarget:self action:@selector(binarySonMax:) forControlEvents:UIControlEventTouchUpInside];
               button.translatesAutoresizingMaskIntoConstraints = NO;
               [button.heightAnchor constraintEqualToConstant:40].active = YES;
               [self.deepFixMovieView addArrangedSubview:button];
           }
       } else {
           
           self.deepFixMovieView = [[UIStackView alloc] init];
           self.deepFixMovieView.axis = UILayoutConstraintAxisVertical;
           self.deepFixMovieView.spacing = 1;
           self.deepFixMovieView.distribution = UIStackViewDistributionFillEqually;
           self.deepFixMovieView.translatesAutoresizingMaskIntoConstraints = NO;
           [self.wetNotBedColorView addSubview:self.deepFixMovieView];
           
           NSLayoutYAxisAnchor *lighterCentersBuffersSlowStepchild = wetMolarView ? wetMolarView.bottomAnchor : self.wetNotBedColorView.topAnchor;
           [NSLayoutConstraint activateConstraints:@[
               [self.deepFixMovieView.topAnchor constraintEqualToAnchor:lighterCentersBuffersSlowStepchild constant:cloudyItalianFitNearNeutral],
               [self.deepFixMovieView.leadingAnchor constraintEqualToAnchor:self.wetNotBedColorView.leadingAnchor],
               [self.deepFixMovieView.trailingAnchor constraintEqualToAnchor:self.wetNotBedColorView.trailingAnchor],
               [self.deepFixMovieView.bottomAnchor constraintEqualToAnchor:self.wetNotBedColorView.bottomAnchor]
           ]];
           
           for (NSInteger i = 0; i < tryGetAmount.count; i++) {
               NSString *mutation = tryGetAmount[i];
               UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
               [button setTitle:mutation forState:UIControlStateNormal];
               button.titleLabel.font = [UIFont systemFontOfSize:17];
               [button setTitleColor:[RuleListCut slopeLockColor] forState:UIControlStateNormal];
               [button setTitleColor:UIColor.lightGrayColor forState:UIControlStateHighlighted];
               button.backgroundColor = [UIColor whiteColor];
               button.tag = i;
               [button addTarget:self action:@selector(binarySonMax:) forControlEvents:UIControlEventTouchUpInside];
               button.translatesAutoresizingMaskIntoConstraints = NO;
               [button.heightAnchor constraintEqualToConstant:40].active = YES;
               [self.deepFixMovieView addArrangedSubview:button];
           }
       }
    }
    return self;
}

- (void)binarySonMax:(UIButton *)sender {
    
    [UIView animateWithDuration:0.25 animations:^{
        self.alpha = 0;
    } completion:^(BOOL finished) {
        [PopParserManager.shared quitTwistJobWindow];
        
        if (self.completion) {
            self.completion(sender.tag);
        }
    }];
}

+ (void)artFourBarUnitSeeWill:(NSString *)title
                        message:(NSString *)message
                   tryGetAmount:(NSArray<NSString *> *)tryGetAmount
                     completion:(JobRetryPartnerPassivelyFloaterParagraph)completion {
    
    LowAlertView *stake = [[LowAlertView alloc] initWithFrame:[UIScreen mainScreen].bounds
                                                 title:title
                                               message:message
                                          tryGetAmount:tryGetAmount
                                            completion:completion];
    
    
    [PopParserManager.shared pinkBinMenstrualStartupDetailedEraView:stake];
    
    
    stake.alpha = 0.0;
    [UIView animateWithDuration:0.25 animations:^{
        stake.alpha = 1.0;
    }];
}

+ (void)artFourBarUnitSeeWill:(NSString *)title message:(NSString *)message completion:(JobRetryPartnerPassivelyFloaterParagraph)completion {
    [self artFourBarUnitSeeWill:title message:message tryGetAmount:@[RuleListCut.costSonKnowKit.noteSum] completion:completion];
}

@end
