






#import "KinAlertView.h"
#import "AppleNotify.h"
#import "FeedSerifManager.h"
#import "Masonry.h"

#define lawRows(fat) __weak typeof(fat) weak##fat = fat;
#define veryAngle(fat) __strong typeof(fat) fat = weak##fat;

@interface KinAlertView()

@property (nonatomic, strong) UIView *goalPanMoreTheView;
@property (nonatomic, copy) ClippingTagsExternComputerBounceDid completion;
@property (nonatomic, strong) UIStackView *finalFeedDueView;

@end

@implementation KinAlertView

- (void)dealloc {
    
}

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

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

+ (void)deliveredFeaturesHailGlucosePhaseFinger:(NSString *)title
                        message:(NSString *)message
                   goalUpdating:(NSArray<NSString *> *)goalUpdating
                     completion:(ClippingTagsExternComputerBounceDid)completion {
    
    KinAlertView *cross = [[KinAlertView alloc] initWithFrame:[UIScreen mainScreen].bounds
                                                 title:title
                                               message:message
                                          goalUpdating:goalUpdating
                                            completion:completion];
    
    
    [FeedSerifManager.shared styleLastSeasonAirIrishDidView:cross];
    
    
    cross.alpha = 0.0;
    [UIView animateWithDuration:0.25 animations:^{
        cross.alpha = 1.0;
    }];
}

+ (void)deliveredFeaturesHailGlucosePhaseFinger:(NSString *)title message:(NSString *)message completion:(ClippingTagsExternComputerBounceDid)completion {
    [self deliveredFeaturesHailGlucosePhaseFinger:title message:message goalUpdating:@[AppleNotify.labelBrownCurl.escaped] completion:completion];
}

@end
