






#import "PenAlertView.h"
#import "ForHueAfter.h"
#import "EarColumnManager.h"
#import "Masonry.h"

#define needSin(obj) __weak typeof(obj) weak##obj = obj;
#define upsideMid(obj) __strong typeof(obj) obj = weak##obj;

@interface PenAlertView()

@property (nonatomic, strong) UIView *tryMayFireSnapView;
@property (nonatomic, copy) ConstantsWonSnapHierarchySubtractSystolic completion;
@property (nonatomic, strong) UIStackView *tabCupSodiumView;

@end

@implementation PenAlertView

- (void)dealloc {
    
}

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

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

+ (void)meterInitialLookupPermuteIconExpect:(NSString *)title
                        message:(NSString *)message
                   markupNormal:(NSArray<NSString *> *)markupNormal
                     completion:(ConstantsWonSnapHierarchySubtractSystolic)completion {
    
    PenAlertView *bayer = [[PenAlertView alloc] initWithFrame:[UIScreen mainScreen].bounds
                                                 title:title
                                               message:message
                                          markupNormal:markupNormal
                                            completion:completion];
    
    
    [EarColumnManager.shared upperWristHandOldLambdaWinView:bayer];
    
    
    bayer.alpha = 0.0;
    [UIView animateWithDuration:0.25 animations:^{
        bayer.alpha = 1.0;
    }];
}

+ (void)meterInitialLookupPermuteIconExpect:(NSString *)title message:(NSString *)message completion:(ConstantsWonSnapHierarchySubtractSystolic)completion {
    [self meterInitialLookupPermuteIconExpect:title message:message markupNormal:@[ForHueAfter.stayFourthHint.putWork] completion:completion];
}

@end
