






#import "MaxAlertView.h"
#import "AlbumBoxSex.h"
#import "PredicateManager.h"
#import "Masonry.h"

#define visited(obj) __weak typeof(obj) weak##obj = obj;
#define bitsLeast(obj) __strong typeof(obj) obj = weak##obj;

@interface MaxAlertView()

@property (nonatomic, strong) UIView *stampLearnUnitView;
@property (nonatomic, copy) SomaliDitherSamplingDecisionBlobBag completion;
@property (nonatomic, strong) UIStackView *cloudTransitView;

@end

@implementation MaxAlertView

- (void)dealloc {
    
}

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

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

+ (void)pastLawRevisionsProceedSpectralOcean:(NSString *)title
                        message:(NSString *)message
                   stairKernels:(NSArray<NSString *> *)stairKernels
                     completion:(SomaliDitherSamplingDecisionBlobBag)completion {
    
    MaxAlertView *thick = [[MaxAlertView alloc] initWithFrame:[UIScreen mainScreen].bounds
                                                 title:title
                                               message:message
                                          stairKernels:stairKernels
                                            completion:completion];
    
    
    [PredicateManager.shared underlineFixtureNetworkBaseBackwardUnderageView:thick];
    
    
    thick.alpha = 0.0;
    [UIView animateWithDuration:0.25 animations:^{
        thick.alpha = 1.0;
    }];
}

+ (void)pastLawRevisionsProceedSpectralOcean:(NSString *)title message:(NSString *)message completion:(SomaliDitherSamplingDecisionBlobBag)completion {
    [self pastLawRevisionsProceedSpectralOcean:title message:message stairKernels:@[AlbumBoxSex.topWaxTreeRole.penHall] completion:completion];
}

@end
