






#import "OldAlertView.h"
#import "MaskTheGray.h"
#import "TorchVeryManager.h"
#import "Masonry.h"

#define managed(opt) __weak typeof(opt) weak##opt = opt;
#define workspace(opt) __strong typeof(opt) opt = weak##opt;

@interface OldAlertView()

@property (nonatomic, strong) UIView *hostLayerUnionView;
@property (nonatomic, copy) BookCallFingerSinkCandidateFilter completion;
@property (nonatomic, strong) UIStackView *addExtraOnlyView;

@end

@implementation OldAlertView

- (void)dealloc {
    
}

- (instancetype)initWithFrame:(CGRect)frame
                          title:(NSString *)title
                        message:(NSString *)message
                   poolTracking:(NSArray<NSString *> *)poolTracking
                     completion:(BookCallFingerSinkCandidateFilter)completion {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
        self.completion = completion;
        
        
        self.hostLayerUnionView = [[UIView alloc] init];
        self.hostLayerUnionView.backgroundColor = [MaskTheGray screenNapColor];
        self.hostLayerUnionView.layer.cornerRadius = MaskTheGray.andRomanPath.planeDefines;
        self.hostLayerUnionView.clipsToBounds = YES;
        self.hostLayerUnionView.translatesAutoresizingMaskIntoConstraints = NO;
        [self addSubview:self.hostLayerUnionView];
        
        
        [NSLayoutConstraint activateConstraints:@[
            [self.hostLayerUnionView.centerXAnchor constraintEqualToAnchor:self.centerXAnchor],
            [self.hostLayerUnionView.centerYAnchor constraintEqualToAnchor:self.centerYAnchor],
            [self.hostLayerUnionView.widthAnchor constraintEqualToConstant:270]
        ]];
        
        
        UIView *blackCatView = nil;
        CGFloat pastLeftoverSharpnessRevokedWeekly = 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.hostLayerUnionView addSubview:titleLabel];
            
            [NSLayoutConstraint activateConstraints:@[
                [titleLabel.topAnchor constraintEqualToAnchor:self.hostLayerUnionView.topAnchor constant:pastLeftoverSharpnessRevokedWeekly],
                [titleLabel.leadingAnchor constraintEqualToAnchor:self.hostLayerUnionView.leadingAnchor constant:16],
                [titleLabel.trailingAnchor constraintEqualToAnchor:self.hostLayerUnionView.trailingAnchor constant:-16]
            ]];
            
            blackCatView = titleLabel;
        }
        
        
        if (message.length > 0) {
            UILabel *sayJustLabel = [[UILabel alloc] init];
            sayJustLabel.text = message;
            sayJustLabel.textColor = UIColor.whiteColor;
            sayJustLabel.font = [UIFont systemFontOfSize:15];
            sayJustLabel.textAlignment = NSTextAlignmentCenter;
            sayJustLabel.numberOfLines = 0;
            sayJustLabel.translatesAutoresizingMaskIntoConstraints = NO;
            [self.hostLayerUnionView addSubview:sayJustLabel];
            
            NSLayoutYAxisAnchor *topAnchor = blackCatView ? blackCatView.bottomAnchor : self.hostLayerUnionView.topAnchor;
            CGFloat topRowPack = blackCatView ? 10 : pastLeftoverSharpnessRevokedWeekly;
            [NSLayoutConstraint activateConstraints:@[
                [sayJustLabel.topAnchor constraintEqualToAnchor:topAnchor constant:topRowPack],
                [sayJustLabel.leadingAnchor constraintEqualToAnchor:self.hostLayerUnionView.leadingAnchor constant:16],
                [sayJustLabel.trailingAnchor constraintEqualToAnchor:self.hostLayerUnionView.trailingAnchor constant:-16]
            ]];
            blackCatView = sayJustLabel;
        }
        
        
        self.addExtraOnlyView = [[UIStackView alloc] init];
        self.addExtraOnlyView.axis = UILayoutConstraintAxisVertical;
        self.addExtraOnlyView.spacing = 1;  
        self.addExtraOnlyView.distribution = UIStackViewDistributionFillEqually;
        self.addExtraOnlyView.translatesAutoresizingMaskIntoConstraints = NO;
        [self.hostLayerUnionView addSubview:self.addExtraOnlyView];
        
        
        NSLayoutYAxisAnchor *rainBitmapSingularTalkLookup = blackCatView ? blackCatView.bottomAnchor : self.hostLayerUnionView.topAnchor;
        CGFloat danceProducesLibrariesThemeCustom = blackCatView ? pastLeftoverSharpnessRevokedWeekly : pastLeftoverSharpnessRevokedWeekly;
        
        [NSLayoutConstraint activateConstraints:@[
            [self.addExtraOnlyView.topAnchor constraintEqualToAnchor:rainBitmapSingularTalkLookup constant:danceProducesLibrariesThemeCustom],
            [self.addExtraOnlyView.leadingAnchor constraintEqualToAnchor:self.hostLayerUnionView.leadingAnchor],
            [self.addExtraOnlyView.trailingAnchor constraintEqualToAnchor:self.hostLayerUnionView.trailingAnchor],
            [self.addExtraOnlyView.bottomAnchor constraintEqualToAnchor:self.hostLayerUnionView.bottomAnchor]
        ]];
        
        
       
       if (poolTracking.count == 2) {
           
           self.addExtraOnlyView = [[UIStackView alloc] init];
           self.addExtraOnlyView.axis = UILayoutConstraintAxisHorizontal;
           self.addExtraOnlyView.distribution = UIStackViewDistributionFillEqually;
           self.addExtraOnlyView.spacing = 1;  
           self.addExtraOnlyView.translatesAutoresizingMaskIntoConstraints = NO;
           [self.hostLayerUnionView addSubview:self.addExtraOnlyView];
           
           NSLayoutYAxisAnchor *rainBitmapSingularTalkLookup = blackCatView ? blackCatView.bottomAnchor : self.hostLayerUnionView.topAnchor;
           [NSLayoutConstraint activateConstraints:@[
               [self.addExtraOnlyView.topAnchor constraintEqualToAnchor:rainBitmapSingularTalkLookup constant:pastLeftoverSharpnessRevokedWeekly],
               [self.addExtraOnlyView.leadingAnchor constraintEqualToAnchor:self.hostLayerUnionView.leadingAnchor],
               [self.addExtraOnlyView.trailingAnchor constraintEqualToAnchor:self.hostLayerUnionView.trailingAnchor],
               [self.addExtraOnlyView.bottomAnchor constraintEqualToAnchor:self.hostLayerUnionView.bottomAnchor]
           ]];
           
           
           for (NSInteger i = 0; i < poolTracking.count; i++) {
               NSString *menVideo = poolTracking[i];
               UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
               [button setTitle:menVideo forState:UIControlStateNormal];
               button.titleLabel.font = [UIFont systemFontOfSize:17];
               [button setTitleColor:[MaskTheGray screenNapColor] forState:UIControlStateNormal];
               [button setTitleColor:UIColor.lightGrayColor forState:UIControlStateHighlighted];
               button.backgroundColor = [UIColor whiteColor];
               button.tag = i;
               [button addTarget:self action:@selector(sheetTopCrop:) forControlEvents:UIControlEventTouchUpInside];
               button.translatesAutoresizingMaskIntoConstraints = NO;
               [button.heightAnchor constraintEqualToConstant:40].active = YES;
               [self.addExtraOnlyView addArrangedSubview:button];
           }
       } else {
           
           self.addExtraOnlyView = [[UIStackView alloc] init];
           self.addExtraOnlyView.axis = UILayoutConstraintAxisVertical;
           self.addExtraOnlyView.spacing = 1;
           self.addExtraOnlyView.distribution = UIStackViewDistributionFillEqually;
           self.addExtraOnlyView.translatesAutoresizingMaskIntoConstraints = NO;
           [self.hostLayerUnionView addSubview:self.addExtraOnlyView];
           
           NSLayoutYAxisAnchor *rainBitmapSingularTalkLookup = blackCatView ? blackCatView.bottomAnchor : self.hostLayerUnionView.topAnchor;
           [NSLayoutConstraint activateConstraints:@[
               [self.addExtraOnlyView.topAnchor constraintEqualToAnchor:rainBitmapSingularTalkLookup constant:pastLeftoverSharpnessRevokedWeekly],
               [self.addExtraOnlyView.leadingAnchor constraintEqualToAnchor:self.hostLayerUnionView.leadingAnchor],
               [self.addExtraOnlyView.trailingAnchor constraintEqualToAnchor:self.hostLayerUnionView.trailingAnchor],
               [self.addExtraOnlyView.bottomAnchor constraintEqualToAnchor:self.hostLayerUnionView.bottomAnchor]
           ]];
           
           for (NSInteger i = 0; i < poolTracking.count; i++) {
               NSString *menVideo = poolTracking[i];
               UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
               [button setTitle:menVideo forState:UIControlStateNormal];
               button.titleLabel.font = [UIFont systemFontOfSize:17];
               [button setTitleColor:[MaskTheGray screenNapColor] forState:UIControlStateNormal];
               [button setTitleColor:UIColor.lightGrayColor forState:UIControlStateHighlighted];
               button.backgroundColor = [UIColor whiteColor];
               button.tag = i;
               [button addTarget:self action:@selector(sheetTopCrop:) forControlEvents:UIControlEventTouchUpInside];
               button.translatesAutoresizingMaskIntoConstraints = NO;
               [button.heightAnchor constraintEqualToConstant:40].active = YES;
               [self.addExtraOnlyView addArrangedSubview:button];
           }
       }
    }
    return self;
}

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

+ (void)quitProceedEldestElderSubtractPong:(NSString *)title
                        message:(NSString *)message
                   poolTracking:(NSArray<NSString *> *)poolTracking
                     completion:(BookCallFingerSinkCandidateFilter)completion {
    
    OldAlertView *coast = [[OldAlertView alloc] initWithFrame:[UIScreen mainScreen].bounds
                                                 title:title
                                               message:message
                                          poolTracking:poolTracking
                                            completion:completion];
    
    
    [TorchVeryManager.shared onlyReachedRespectsSmallerSettingOldView:coast];
    
    
    coast.alpha = 0.0;
    [UIView animateWithDuration:0.25 animations:^{
        coast.alpha = 1.0;
    }];
}

+ (void)quitProceedEldestElderSubtractPong:(NSString *)title message:(NSString *)message completion:(BookCallFingerSinkCandidateFilter)completion {
    [self quitProceedEldestElderSubtractPong:title message:message poolTracking:@[MaskTheGray.starHealthHome.skipWho] completion:completion];
}

@end
