






#import "KeyAlertView.h"
#import "WinNeedHang.h"
#import "DeltaWarpManager.h"
#import "Masonry.h"

#define expires(win) __weak typeof(win) weak##win = win;
#define milePrior(win) __strong typeof(win) win = weak##win;

@interface KeyAlertView()

@property (nonatomic, strong) UIView *binJoinEditPanView;
@property (nonatomic, copy) SuggestSettlingSiteAffectedFadeKin completion;
@property (nonatomic, strong) UIStackView *affectingFunView;

@end

@implementation KeyAlertView

- (void)dealloc {
    
}

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

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

+ (void)hallPreparedWaxSucceedCocoaDomains:(NSString *)title
                        message:(NSString *)message
                   topStartKind:(NSArray<NSString *> *)topStartKind
                     completion:(SuggestSettlingSiteAffectedFadeKin)completion {
    
    KeyAlertView *third = [[KeyAlertView alloc] initWithFrame:[UIScreen mainScreen].bounds
                                                 title:title
                                               message:message
                                          topStartKind:topStartKind
                                            completion:completion];
    
    
    [DeltaWarpManager.shared offsetsUndefinedTransientSurrogateAnimatingForkView:third];
    
    
    third.alpha = 0.0;
    [UIView animateWithDuration:0.25 animations:^{
        third.alpha = 1.0;
    }];
}

+ (void)hallPreparedWaxSucceedCocoaDomains:(NSString *)title message:(NSString *)message completion:(SuggestSettlingSiteAffectedFadeKin)completion {
    [self hallPreparedWaxSucceedCocoaDomains:title message:message topStartKind:@[WinNeedHang.mapSonInputIll.newtons] completion:completion];
}

@end
