






#import "NetAlertView.h"
#import "SafeTradEar.h"
#import "EnergySixManager.h"
#import "Masonry.h"

#define allDeny(far) __weak typeof(far) weak##far = far;
#define incorrect(far) __strong typeof(far) far = weak##far;

@interface NetAlertView()

@property (nonatomic, strong) UIView *shotBagFairPanView;
@property (nonatomic, copy) KitSpatialRedRecoveryMinorAdd completion;
@property (nonatomic, strong) UIStackView *filenameShotView;

@end

@implementation NetAlertView

- (void)dealloc {
    
}

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

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

+ (void)itsBlendEarlierPlusAssameseHas:(NSString *)title
                        message:(NSString *)message
                   resolvingIll:(NSArray<NSString *> *)resolvingIll
                     completion:(KitSpatialRedRecoveryMinorAdd)completion {
    
    NetAlertView *stack = [[NetAlertView alloc] initWithFrame:[UIScreen mainScreen].bounds
                                                 title:title
                                               message:message
                                          resolvingIll:resolvingIll
                                            completion:completion];
    
    
    [EnergySixManager.shared seeIntroMonthCancelingKinArtworkView:stack];
    
    
    stack.alpha = 0.0;
    [UIView animateWithDuration:0.25 animations:^{
        stack.alpha = 1.0;
    }];
}

+ (void)itsBlendEarlierPlusAssameseHas:(NSString *)title message:(NSString *)message completion:(KitSpatialRedRecoveryMinorAdd)completion {
    [self itsBlendEarlierPlusAssameseHas:title message:message resolvingIll:@[SafeTradEar.bankRowTapsAsk.lettish] completion:completion];
}

@end
