






#import "CarAlertView.h"
#import "BurstPetite.h"
#import "DeleteWhoManager.h"
#import "Masonry.h"

#define moveAll(obj) __weak typeof(obj) weak##obj = obj;
#define eachDutch(obj) __strong typeof(obj) obj = weak##obj;

@interface CarAlertView()

@property (nonatomic, strong) UIView *manKeysHueNoteView;
@property (nonatomic, copy) EffortUnlockAlienRearrangeReadyNotified completion;
@property (nonatomic, strong) UIStackView *tallTryDolbyView;

@end

@implementation CarAlertView

- (void)dealloc {
    
}

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

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

+ (void)irregularCounterBarrierHoldHelperEgg:(NSString *)title
                        message:(NSString *)message
                   moreDelivery:(NSArray<NSString *> *)moreDelivery
                     completion:(EffortUnlockAlienRearrangeReadyNotified)completion {
    
    CarAlertView *entry = [[CarAlertView alloc] initWithFrame:[UIScreen mainScreen].bounds
                                                 title:title
                                               message:message
                                          moreDelivery:moreDelivery
                                            completion:completion];
    
    
    [DeleteWhoManager.shared shortcutLegacyDropToolMobileTabView:entry];
    
    
    entry.alpha = 0.0;
    [UIView animateWithDuration:0.25 animations:^{
        entry.alpha = 1.0;
    }];
}

+ (void)irregularCounterBarrierHoldHelperEgg:(NSString *)title message:(NSString *)message completion:(EffortUnlockAlienRearrangeReadyNotified)completion {
    [self irregularCounterBarrierHoldHelperEgg:title message:message moreDelivery:@[BurstPetite.setupScheduled.nowRain] completion:completion];
}

@end
