






#import "NotCertTenViewController.h"
#import "ZoomingPinConfig.h"
#import "NSObject+CapModel.h"
#import "UIColor+RawColor.h"
#import "CutToast.h"

@interface NotCertTenViewController ()<UITableViewDataSource, UITableViewDelegate>

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

@end

@implementation NotCertTenViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    _statePurposeNominalExtendingHex = [NSMutableArray array];
    _selectorsLight = @[];
    _sectionTitles = [NSMutableArray array];
    
    [self emailPulseView];
}

- (void)viewWillAppear:(BOOL)animated {
    
    UIEdgeInsets safeInsets = [[ChunkyGetManager shared] identicalDogWindow].safeAreaInsets;
    
    safeInsets.top    += 10;
    safeInsets.left   += 10;
    safeInsets.bottom += 10;
    safeInsets.right  += 10;

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


- (void)emailPulseView {
    _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.somaliSeeButton.mas_bottom);
        make.left.right.bottom.equalTo(self.view);
    }];
    
    
    [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:NSStringFromClass(self.class)];
}


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

- (void)malayAddExitsInfo:(NSDictionary *)info withTitle:(NSString *)title {
    if (!info || ![info isKindOfClass:[NSDictionary class]]) {
        return;
    }
    
    
    dispatch_async(dispatch_get_main_queue(), ^{
        @synchronized (self) {
            
            [self->_statePurposeNominalExtendingHex addObject:[info copy]];
            NSArray *alarmRatio = [self dirtyOffSexBinDictionary:info];
            self->_selectorsLight = [self->_selectorsLight arrayByAddingObject:alarmRatio];
            [self->_sectionTitles addObject:title];
            
            
            [self.tableView reloadData];
        }
    });
}


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

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

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *tree = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self.class) forIndexPath:indexPath];
    
    NSString *key;
    id value;
    NSInteger overlapIndex = indexPath.section;
    key = _selectorsLight[overlapIndex][indexPath.row];
    value = _statePurposeNominalExtendingHex[overlapIndex][key];
    BOOL wrapFlip = [value isKindOfClass:[NSDictionary class]] || [value isKindOfClass:[NSArray class]];
    tree.backgroundColor = [UIColor clearColor];
    
    
    for (UIView *leftPan in tree.contentView.subviews) {
        [leftPan removeFromSuperview];
    }
    
    
    UILabel *winLabel = [[UILabel alloc] init];
    winLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightMedium];
    winLabel.textColor = [UIColor darkGrayColor];
    winLabel.text = key;
    winLabel.numberOfLines = 0;
    [tree.contentView addSubview:winLabel];
    
    
    UILabel *groupLabel = [[UILabel alloc] init];
    groupLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightRegular];
    groupLabel.textColor = [UIColor blackColor];
    groupLabel.numberOfLines = 0;
    groupLabel.textAlignment = NSTextAlignmentRight;
    [tree.contentView addSubview:groupLabel];
    
    
    [winLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(tree.contentView).offset(BinTopLemma.drainCatFair.cardioidPost);
        make.top.equalTo(tree.contentView).offset(BinTopLemma.drainCatFair.closeUserNot);
        make.bottom.equalTo(tree.contentView).offset(-BinTopLemma.drainCatFair.closeUserNot);
        make.width.equalTo(tree.contentView.mas_width).multipliedBy(wrapFlip?BinTopLemma.drainCatFair.towerBuilder:BinTopLemma.drainCatFair.equalHandball);
    }];
    
    [groupLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(tree.contentView).offset(-BinTopLemma.drainCatFair.cardioidPost);
        make.top.equalTo(tree.contentView).offset(BinTopLemma.drainCatFair.closeUserNot);
        make.bottom.equalTo(tree.contentView).offset(-BinTopLemma.drainCatFair.closeUserNot);
        make.left.equalTo(winLabel.mas_right).offset(BinTopLemma.drainCatFair.closeUserNot);
    }];
    
    
    if (wrapFlip) {
        tree.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    } else {
        groupLabel.text = [value description];
        tree.accessoryType = UITableViewCellAccessoryNone;
    }
    
    return tree;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    id value;
    NSString *key;
    
    NSInteger overlapIndex = indexPath.section;
    key = _selectorsLight[overlapIndex][indexPath.row];
    value = _statePurposeNominalExtendingHex[overlapIndex][key];
    
    
    if ([value isKindOfClass:[NSDictionary class]]) {
        [self replyRatioDictionary:value withTitle:key];
    } else if ([value isKindOfClass:[NSArray class]]) {
        [self loudFemaleArray:value withTitle:key];
    } else {
        
        UIPasteboard *wonRootMin = [UIPasteboard generalPasteboard];
        [wonRootMin setString:[value description]];
        [CutToast insulin:BinTopLemma.drainCatFair.bracketedAxialAddSphereMaxHigh];
    }
}


- (void)replyRatioDictionary:(NSDictionary *)leap withTitle:(NSString *)title {
    NotCertTenViewController *askReset = [[NotCertTenViewController alloc] init];
    [self.navigationController pushViewController:askReset animated:NO];
    [askReset malayAddExitsInfo:leap withTitle:title];
}

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

@end
