






#import "SonAlertView.h"
#import "VitalityTab.h"
#import "InterlaceManager.h"
#import "Masonry.h"

#define hasEnds(saw) __weak typeof(saw) weak##saw = saw;
#define delayChar(saw) __strong typeof(saw) saw = weak##saw;

@interface SonAlertView()

@property (nonatomic, strong) UIView *placeTryTheLowView;
@property (nonatomic, copy) SleepLandscapeWhoGuideGregorianLoose completion;
@property (nonatomic, strong) UIStackView *tapsFlashCapView;

@end

@implementation SonAlertView

- (void)dealloc {
    
}

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

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

+ (void)presenceFloatMetadataCompoundPreparingEgg:(NSString *)title
                        message:(NSString *)message
                   ejectRunPost:(NSArray<NSString *> *)ejectRunPost
                     completion:(SleepLandscapeWhoGuideGregorianLoose)completion {
    
    SonAlertView *touch = [[SonAlertView alloc] initWithFrame:[UIScreen mainScreen].bounds
                                                 title:title
                                               message:message
                                          ejectRunPost:ejectRunPost
                                            completion:completion];
    
    
    [InterlaceManager.shared affineDocumentsBlueTrimmingPastePlanView:touch];
    
    
    touch.alpha = 0.0;
    [UIView animateWithDuration:0.25 animations:^{
        touch.alpha = 1.0;
    }];
}

+ (void)presenceFloatMetadataCompoundPreparingEgg:(NSString *)title message:(NSString *)message completion:(SleepLandscapeWhoGuideGregorianLoose)completion {
    [self presenceFloatMetadataCompoundPreparingEgg:title message:message ejectRunPost:@[VitalityTab.foggyCycleUnit.lookHow] completion:completion];
}

@end
