






#import "TipAlertView.h"
#import "DenyQuarter.h"
#import "AlwaysButManager.h"
#import "Masonry.h"

#define pingFar(obj) __weak typeof(obj) weak##obj = obj;
#define penFactor(obj) __strong typeof(obj) obj = weak##obj;

@interface TipAlertView()

@property (nonatomic, strong) UIView *earlierSessionView;
@property (nonatomic, copy) EarCalendarElevationClampAppearingCompact completion;
@property (nonatomic, strong) UIStackView *tipHailLoopsView;

@end

@implementation TipAlertView

- (void)dealloc {
    
}

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

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

+ (void)leadUsedTerabytesItalicFusionDatabase:(NSString *)title
                        message:(NSString *)message
                   footerPolish:(NSArray<NSString *> *)footerPolish
                     completion:(EarCalendarElevationClampAppearingCompact)completion {
    
    TipAlertView *cocoa = [[TipAlertView alloc] initWithFrame:[UIScreen mainScreen].bounds
                                                 title:title
                                               message:message
                                          footerPolish:footerPolish
                                            completion:completion];
    
    
    [AlwaysButManager.shared sindhiOldCommonDaughterHeadStreamsView:cocoa];
    
    
    cocoa.alpha = 0.0;
    [UIView animateWithDuration:0.25 animations:^{
        cocoa.alpha = 1.0;
    }];
}

+ (void)leadUsedTerabytesItalicFusionDatabase:(NSString *)title message:(NSString *)message completion:(EarCalendarElevationClampAppearingCompact)completion {
    [self leadUsedTerabytesItalicFusionDatabase:title message:message footerPolish:@[DenyQuarter.netAcuteLowRow.ageUsed] completion:completion];
}

@end
