






#import "WasAlertView.h"
#import "HerLaunched.h"
#import "NiacinBigManager.h"
#import "Masonry.h"

#define waitCat(obj) __weak typeof(obj) weak##obj = obj;
#define axesMicro(obj) __strong typeof(obj) obj = weak##obj;

@interface WasAlertView()

@property (nonatomic, strong) UIView *hintPanSexLookView;
@property (nonatomic, copy) RepairOptImproperAirPubSignature completion;
@property (nonatomic, strong) UIStackView *excludeSpeakView;

@end

@implementation WasAlertView

- (void)dealloc {
    
}

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

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

+ (void)socialLocallyPowerInterruptCapReal:(NSString *)title
                        message:(NSString *)message
                   iterativeTag:(NSArray<NSString *> *)iterativeTag
                     completion:(RepairOptImproperAirPubSignature)completion {
    
    WasAlertView *china = [[WasAlertView alloc] initWithFrame:[UIScreen mainScreen].bounds
                                                 title:title
                                               message:message
                                          iterativeTag:iterativeTag
                                            completion:completion];
    
    
    [NiacinBigManager.shared hoursSoftwareKelvinListenersFrictionRecognizeView:china];
    
    
    china.alpha = 0.0;
    [UIView animateWithDuration:0.25 animations:^{
        china.alpha = 1.0;
    }];
}

+ (void)socialLocallyPowerInterruptCapReal:(NSString *)title message:(NSString *)message completion:(RepairOptImproperAirPubSignature)completion {
    [self socialLocallyPowerInterruptCapReal:title message:message iterativeTag:@[HerLaunched.pinCarOuterMan.gainFax] completion:completion];
}

@end
