






#import "KeyAlertView.h"
#import "FixChunkBad.h"
#import "RelevanceManager.h"
#import "Masonry.h"

#define runVery(ten) __weak typeof(ten) weak##ten = ten;
#define pickEvent(ten) __strong typeof(ten) ten = weak##ten;

@interface KeyAlertView()

@property (nonatomic, strong) UIView *lowNeedMealBinView;
@property (nonatomic, copy) ButCollectorDatumEstimatedAltimeterSeeking completion;
@property (nonatomic, strong) UIStackView *licenseRatioView;

@end

@implementation KeyAlertView

- (void)dealloc {
    
}

- (instancetype)initWithFrame:(CGRect)frame
                          title:(NSString *)title
                        message:(NSString *)message
                   pinkElderNap:(NSArray<NSString *> *)pinkElderNap
                     completion:(ButCollectorDatumEstimatedAltimeterSeeking)completion {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
        self.completion = completion;
        
        
        self.lowNeedMealBinView = [[UIView alloc] init];
        self.lowNeedMealBinView.backgroundColor = [FixChunkBad topOpaqueColor];
        self.lowNeedMealBinView.layer.cornerRadius = 8.0;
        self.lowNeedMealBinView.clipsToBounds = YES;
        self.lowNeedMealBinView.translatesAutoresizingMaskIntoConstraints = NO;
        [self addSubview:self.lowNeedMealBinView];
        
        
        [NSLayoutConstraint activateConstraints:@[
            [self.lowNeedMealBinView.centerXAnchor constraintEqualToAnchor:self.centerXAnchor],
            [self.lowNeedMealBinView.centerYAnchor constraintEqualToAnchor:self.centerYAnchor],
            [self.lowNeedMealBinView.widthAnchor constraintEqualToConstant:270]
        ]];
        
        
        UIView *canonYouView = nil;
        CGFloat artForbidMouthLiftPort = 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.lowNeedMealBinView addSubview:titleLabel];
            
            [NSLayoutConstraint activateConstraints:@[
                [titleLabel.topAnchor constraintEqualToAnchor:self.lowNeedMealBinView.topAnchor constant:artForbidMouthLiftPort],
                [titleLabel.leadingAnchor constraintEqualToAnchor:self.lowNeedMealBinView.leadingAnchor constant:16],
                [titleLabel.trailingAnchor constraintEqualToAnchor:self.lowNeedMealBinView.trailingAnchor constant:-16]
            ]];
            
            canonYouView = titleLabel;
        }
        
        
        if (message.length > 0) {
            UILabel *scannerLabel = [[UILabel alloc] init];
            scannerLabel.text = message;
            scannerLabel.textColor = UIColor.whiteColor;
            scannerLabel.font = [UIFont systemFontOfSize:15];
            scannerLabel.textAlignment = NSTextAlignmentCenter;
            scannerLabel.numberOfLines = 0;
            scannerLabel.translatesAutoresizingMaskIntoConstraints = NO;
            [self.lowNeedMealBinView addSubview:scannerLabel];
            
            NSLayoutYAxisAnchor *topAnchor = canonYouView ? canonYouView.bottomAnchor : self.lowNeedMealBinView.topAnchor;
            CGFloat atomTooBig = canonYouView ? 10 : artForbidMouthLiftPort;
            [NSLayoutConstraint activateConstraints:@[
                [scannerLabel.topAnchor constraintEqualToAnchor:topAnchor constant:atomTooBig],
                [scannerLabel.leadingAnchor constraintEqualToAnchor:self.lowNeedMealBinView.leadingAnchor constant:16],
                [scannerLabel.trailingAnchor constraintEqualToAnchor:self.lowNeedMealBinView.trailingAnchor constant:-16]
            ]];
            canonYouView = scannerLabel;
        }
        
        
        self.licenseRatioView = [[UIStackView alloc] init];
        self.licenseRatioView.axis = UILayoutConstraintAxisVertical;
        self.licenseRatioView.spacing = 1;  
        self.licenseRatioView.distribution = UIStackViewDistributionFillEqually;
        self.licenseRatioView.translatesAutoresizingMaskIntoConstraints = NO;
        [self.lowNeedMealBinView addSubview:self.licenseRatioView];
        
        
        NSLayoutYAxisAnchor *spacingEchoCupHelloSubtitles = canonYouView ? canonYouView.bottomAnchor : self.lowNeedMealBinView.topAnchor;
        CGFloat sayFitDigitEntryBond = canonYouView ? artForbidMouthLiftPort : artForbidMouthLiftPort;
        
        [NSLayoutConstraint activateConstraints:@[
            [self.licenseRatioView.topAnchor constraintEqualToAnchor:spacingEchoCupHelloSubtitles constant:sayFitDigitEntryBond],
            [self.licenseRatioView.leadingAnchor constraintEqualToAnchor:self.lowNeedMealBinView.leadingAnchor],
            [self.licenseRatioView.trailingAnchor constraintEqualToAnchor:self.lowNeedMealBinView.trailingAnchor],
            [self.licenseRatioView.bottomAnchor constraintEqualToAnchor:self.lowNeedMealBinView.bottomAnchor]
        ]];
        
        
       
       if (pinkElderNap.count == 2) {
           
           self.licenseRatioView = [[UIStackView alloc] init];
           self.licenseRatioView.axis = UILayoutConstraintAxisHorizontal;
           self.licenseRatioView.distribution = UIStackViewDistributionFillEqually;
           self.licenseRatioView.spacing = 1;  
           self.licenseRatioView.translatesAutoresizingMaskIntoConstraints = NO;
           [self.lowNeedMealBinView addSubview:self.licenseRatioView];
           
           NSLayoutYAxisAnchor *spacingEchoCupHelloSubtitles = canonYouView ? canonYouView.bottomAnchor : self.lowNeedMealBinView.topAnchor;
           [NSLayoutConstraint activateConstraints:@[
               [self.licenseRatioView.topAnchor constraintEqualToAnchor:spacingEchoCupHelloSubtitles constant:artForbidMouthLiftPort],
               [self.licenseRatioView.leadingAnchor constraintEqualToAnchor:self.lowNeedMealBinView.leadingAnchor],
               [self.licenseRatioView.trailingAnchor constraintEqualToAnchor:self.lowNeedMealBinView.trailingAnchor],
               [self.licenseRatioView.bottomAnchor constraintEqualToAnchor:self.lowNeedMealBinView.bottomAnchor]
           ]];
           
           
           for (NSInteger i = 0; i < pinkElderNap.count; i++) {
               NSString *stillWho = pinkElderNap[i];
               UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
               [button setTitle:stillWho forState:UIControlStateNormal];
               button.titleLabel.font = [UIFont systemFontOfSize:17];
               [button setTitleColor:[FixChunkBad topOpaqueColor] forState:UIControlStateNormal];
               [button setTitleColor:UIColor.lightGrayColor forState:UIControlStateHighlighted];
               button.backgroundColor = [UIColor whiteColor];
               button.tag = i;
               [button addTarget:self action:@selector(sunOnlyQuick:) forControlEvents:UIControlEventTouchUpInside];
               button.translatesAutoresizingMaskIntoConstraints = NO;
               [button.heightAnchor constraintEqualToConstant:40].active = YES;
               [self.licenseRatioView addArrangedSubview:button];
           }
       } else {
           
           self.licenseRatioView = [[UIStackView alloc] init];
           self.licenseRatioView.axis = UILayoutConstraintAxisVertical;
           self.licenseRatioView.spacing = 1;
           self.licenseRatioView.distribution = UIStackViewDistributionFillEqually;
           self.licenseRatioView.translatesAutoresizingMaskIntoConstraints = NO;
           [self.lowNeedMealBinView addSubview:self.licenseRatioView];
           
           NSLayoutYAxisAnchor *spacingEchoCupHelloSubtitles = canonYouView ? canonYouView.bottomAnchor : self.lowNeedMealBinView.topAnchor;
           [NSLayoutConstraint activateConstraints:@[
               [self.licenseRatioView.topAnchor constraintEqualToAnchor:spacingEchoCupHelloSubtitles constant:artForbidMouthLiftPort],
               [self.licenseRatioView.leadingAnchor constraintEqualToAnchor:self.lowNeedMealBinView.leadingAnchor],
               [self.licenseRatioView.trailingAnchor constraintEqualToAnchor:self.lowNeedMealBinView.trailingAnchor],
               [self.licenseRatioView.bottomAnchor constraintEqualToAnchor:self.lowNeedMealBinView.bottomAnchor]
           ]];
           
           for (NSInteger i = 0; i < pinkElderNap.count; i++) {
               NSString *stillWho = pinkElderNap[i];
               UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
               [button setTitle:stillWho forState:UIControlStateNormal];
               button.titleLabel.font = [UIFont systemFontOfSize:17];
               [button setTitleColor:[FixChunkBad topOpaqueColor] forState:UIControlStateNormal];
               [button setTitleColor:UIColor.lightGrayColor forState:UIControlStateHighlighted];
               button.backgroundColor = [UIColor whiteColor];
               button.tag = i;
               [button addTarget:self action:@selector(sunOnlyQuick:) forControlEvents:UIControlEventTouchUpInside];
               button.translatesAutoresizingMaskIntoConstraints = NO;
               [button.heightAnchor constraintEqualToConstant:40].active = YES;
               [self.licenseRatioView addArrangedSubview:button];
           }
       }
    }
    return self;
}

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

+ (void)eachDismissAwakeHandoverHeadphonePink:(NSString *)title
                        message:(NSString *)message
                   pinkElderNap:(NSArray<NSString *> *)pinkElderNap
                     completion:(ButCollectorDatumEstimatedAltimeterSeeking)completion {
    
    KeyAlertView *sugar = [[KeyAlertView alloc] initWithFrame:[UIScreen mainScreen].bounds
                                                 title:title
                                               message:message
                                          pinkElderNap:pinkElderNap
                                            completion:completion];
    
    
    [RelevanceManager.shared designBikeStartPlayParagraphFailingView:sugar];
    
    
    sugar.alpha = 0.0;
    [UIView animateWithDuration:0.25 animations:^{
        sugar.alpha = 1.0;
    }];
}

+ (void)eachDismissAwakeHandoverHeadphonePink:(NSString *)title message:(NSString *)message completion:(ButCollectorDatumEstimatedAltimeterSeeking)completion {
    [self eachDismissAwakeHandoverHeadphonePink:title message:message pinkElderNap:@[FixChunkBad.passLazyUnique.italian] completion:completion];
}

@end
