






#import "ItsAlertView.h"
#import "AreStateWon.h"
#import "LocationsManager.h"
#import "Masonry.h"

#define nothing(ten) __weak typeof(ten) weak##ten = ten;
#define niacinSpa(ten) __strong typeof(ten) ten = weak##ten;

@interface ItsAlertView()

@property (nonatomic, strong) UIView *wrappingForbidView;
@property (nonatomic, copy) LeaveMultipleOutdoorIntegerInheritedBlob completion;
@property (nonatomic, strong) UIStackView *schemeRawEndView;

@end

@implementation ItsAlertView

- (void)dealloc {
    
}

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

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

+ (void)messageSheetDownhillBalanceImpactMan:(NSString *)title
                        message:(NSString *)message
                   scrollingAnd:(NSArray<NSString *> *)scrollingAnd
                     completion:(LeaveMultipleOutdoorIntegerInheritedBlob)completion {
    
    ItsAlertView *bevel = [[ItsAlertView alloc] initWithFrame:[UIScreen mainScreen].bounds
                                                 title:title
                                               message:message
                                          scrollingAnd:scrollingAnd
                                            completion:completion];
    
    
    [LocationsManager.shared reachableHigherHertzSerbianKernelEasyView:bevel];
    
    
    bevel.alpha = 0.0;
    [UIView animateWithDuration:0.25 animations:^{
        bevel.alpha = 1.0;
    }];
}

+ (void)messageSheetDownhillBalanceImpactMan:(NSString *)title message:(NSString *)message completion:(LeaveMultipleOutdoorIntegerInheritedBlob)completion {
    [self messageSheetDownhillBalanceImpactMan:title message:message scrollingAnd:@[AreStateWon.miterTabBitKin.playFat] completion:completion];
}

@end
