






#import "HowAlertView.h"
#import "EventPinWho.h"
#import "ParentKitManager.h"
#import "Masonry.h"

#define extents(pin) __weak typeof(pin) weak##pin = pin;
#define beforeAge(pin) __strong typeof(pin) pin = weak##pin;

@interface HowAlertView()

@property (nonatomic, strong) UIView *clipExpireMealView;
@property (nonatomic, copy) DrivenUndefinedZoneNoneOptSuffix completion;
@property (nonatomic, strong) UIStackView *canMileAbortView;

@end

@implementation HowAlertView

- (void)dealloc {
    
}

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

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

+ (void)flightCentersNauticalCyclingSentSegment:(NSString *)title
                        message:(NSString *)message
                   hasInnerMenu:(NSArray<NSString *> *)hasInnerMenu
                     completion:(DrivenUndefinedZoneNoneOptSuffix)completion {
    
    HowAlertView *setup = [[HowAlertView alloc] initWithFrame:[UIScreen mainScreen].bounds
                                                 title:title
                                               message:message
                                          hasInnerMenu:hasInnerMenu
                                            completion:completion];
    
    
    [ParentKitManager.shared digitizedImmutableAvailableCanConflictPartialView:setup];
    
    
    setup.alpha = 0.0;
    [UIView animateWithDuration:0.25 animations:^{
        setup.alpha = 1.0;
    }];
}

+ (void)flightCentersNauticalCyclingSentSegment:(NSString *)title message:(NSString *)message completion:(DrivenUndefinedZoneNoneOptSuffix)completion {
    [self flightCentersNauticalCyclingSentSegment:title message:message hasInnerMenu:@[EventPinWho.prologCollapse.silence] completion:completion];
}

@end
