






#import "UighurMaleViewController.h"
#import "TypeHigherConfig.h"
#import "NSObject+HisModel.h"
#import "UIColor+FitColor.h"
#import "PutToast.h"

@interface UighurMaleViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray<NSDictionary *> *shareAllergySystolicDividingPause; 
@property (nonatomic, strong) NSArray<NSArray<NSString *> *> *ratioChildWarn; 
@property (nonatomic, strong) NSMutableArray<NSString *> *sectionTitles; 

@end

@implementation UighurMaleViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    _shareAllergySystolicDividingPause = [NSMutableArray array];
    _ratioChildWarn = @[];
    _sectionTitles = [NSMutableArray array];
    
    [self skipOwnDryView];
}

- (void)viewWillAppear:(BOOL)animated {
    
    UIEdgeInsets fillTenLog = [[CountHostManager shared] maxForceDarkWindow].safeAreaInsets;
    
    fillTenLog.top    += 10;
    fillTenLog.left   += 10;
    fillTenLog.bottom += 10;
    fillTenLog.right  += 10;

    [self.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(fillTenLog);
    }];
}


- (void)skipOwnDryView {
    _tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    _tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    _tableView.dataSource = self;
    _tableView.delegate = self;
    _tableView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:_tableView];
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.stopDrainButton.mas_bottom);
        make.left.right.bottom.equalTo(self.view);
    }];
    
    
    [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:NSStringFromClass(self.class)];
}


- (NSArray<NSString *> *)getFlowItemOurDictionary:(NSDictionary *)burn {
    return [[burn allKeys] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
}

- (void)napTryElapsedInfo:(NSDictionary *)info withTitle:(NSString *)title {
    if (!info || ![info isKindOfClass:[NSDictionary class]]) {
        return;
    }
    
    
    dispatch_async(dispatch_get_main_queue(), ^{
        @synchronized (self) {
            
            [self->_shareAllergySystolicDividingPause addObject:[info copy]];
            NSArray *tryOffsets = [self getFlowItemOurDictionary:info];
            self->_ratioChildWarn = [self->_ratioChildWarn arrayByAddingObject:tryOffsets];
            [self->_sectionTitles addObject:title];
            
            
            [self.tableView reloadData];
        }
    });
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return _shareAllergySystolicDividingPause.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _ratioChildWarn[section].count;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    return _sectionTitles[section];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *turn = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self.class) forIndexPath:indexPath];
    
    NSString *key;
    id value;
    NSInteger entriesIndex = indexPath.section;
    key = _ratioChildWarn[entriesIndex][indexPath.row];
    value = _shareAllergySystolicDividingPause[entriesIndex][key];
    BOOL spaAlert = [value isKindOfClass:[NSDictionary class]] || [value isKindOfClass:[NSArray class]];
    turn.backgroundColor = [UIColor clearColor];
    
    
    for (UIView *divider in turn.contentView.subviews) {
        [divider removeFromSuperview];
    }
    
    
    UILabel *dueLabel = [[UILabel alloc] init];
    dueLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightMedium];
    dueLabel.textColor = [UIColor darkGrayColor];
    dueLabel.text = key;
    dueLabel.numberOfLines = 0;
    [turn.contentView addSubview:dueLabel];
    
    
    UILabel *renewLabel = [[UILabel alloc] init];
    renewLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightRegular];
    renewLabel.textColor = [UIColor blackColor];
    renewLabel.numberOfLines = 0;
    renewLabel.textAlignment = NSTextAlignmentRight;
    [turn.contentView addSubview:renewLabel];
    
    
    [dueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(turn.contentView).offset(HourEllipse.howSignaling.oneWeekProxy);
        make.top.equalTo(turn.contentView).offset(HourEllipse.howSignaling.bundleGlobal);
        make.bottom.equalTo(turn.contentView).offset(-HourEllipse.howSignaling.bundleGlobal);
        make.width.equalTo(turn.contentView.mas_width).multipliedBy(spaAlert?HourEllipse.howSignaling.callingDutch:HourEllipse.howSignaling.tipOwnerRetry);
    }];
    
    [renewLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(turn.contentView).offset(-HourEllipse.howSignaling.oneWeekProxy);
        make.top.equalTo(turn.contentView).offset(HourEllipse.howSignaling.bundleGlobal);
        make.bottom.equalTo(turn.contentView).offset(-HourEllipse.howSignaling.bundleGlobal);
        make.left.equalTo(dueLabel.mas_right).offset(HourEllipse.howSignaling.bundleGlobal);
    }];
    
    
    if (spaAlert) {
        turn.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    } else {
        renewLabel.text = [value description];
        turn.accessoryType = UITableViewCellAccessoryNone;
    }
    
    return turn;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    id value;
    NSString *key;
    
    NSInteger entriesIndex = indexPath.section;
    key = _ratioChildWarn[entriesIndex][indexPath.row];
    value = _shareAllergySystolicDividingPause[entriesIndex][key];
    
    
    if ([value isKindOfClass:[NSDictionary class]]) {
        [self dayWhoMostDictionary:value withTitle:key];
    } else if ([value isKindOfClass:[NSArray class]]) {
        [self overRunAreArray:value withTitle:key];
    } else {
        
        UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
        [pasteboard setString:[value description]];
        [PutToast morePop:HourEllipse.howSignaling.increaseBlendRemovesLateArePast];
    }
}


- (void)dayWhoMostDictionary:(NSDictionary *)burn withTitle:(NSString *)title {
    UighurMaleViewController *heavyYet = [[UighurMaleViewController alloc] init];
    [self.navigationController pushViewController:heavyYet animated:NO];
    [heavyYet napTryElapsedInfo:burn withTitle:title];
}

- (void)overRunAreArray:(NSArray *)array withTitle:(NSString *)title {
    
    NSMutableDictionary *blockDict = [NSMutableDictionary dictionary];
    for (NSInteger i = 0; i < array.count; i++) {
        blockDict[[NSString stringWithFormat:@"[%ld]", (long)i]] = array[i];
    }
    
    UighurMaleViewController *heavyYet = [[UighurMaleViewController alloc] init];
    [self.navigationController pushViewController:heavyYet animated:NO];
    [heavyYet napTryElapsedInfo:blockDict withTitle:[NSString stringWithFormat:@"%@ (Array)", title]];
}

@end
