






#import "KinCharTwoViewController.h"
#import "RedoTabFarConfig.h"
#import "NSObject+TenModel.h"
#import "UIColor+RetColor.h"
#import "WasToast.h"

@interface KinCharTwoViewController ()<UITableViewDataSource, UITableViewDelegate>

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

@end

@implementation KinCharTwoViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    _intentExpandingShakeInitialDominant = [NSMutableArray array];
    _longerDeclined = @[];
    _sectionTitles = [NSMutableArray array];
    
    [self redMileCanView];
}

- (void)viewWillAppear:(BOOL)animated {
    
    UIEdgeInsets offGetBase = [[KeysVoiceManager shared] kilobitsClipWindow].safeAreaInsets;
    
    offGetBase.top    += 10;
    offGetBase.left   += 10;
    offGetBase.bottom += 10;
    offGetBase.right  += 10;

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


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


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

- (void)heavyIllWhiteInfo:(NSDictionary *)info withTitle:(NSString *)title {
    if (!info || ![info isKindOfClass:[NSDictionary class]]) {
        return;
    }
    
    
    dispatch_async(dispatch_get_main_queue(), ^{
        @synchronized (self) {
            
            [self->_intentExpandingShakeInitialDominant addObject:[info copy]];
            NSArray *busCubeMen = [self arrayFocusTagsDictionary:info];
            self->_longerDeclined = [self->_longerDeclined arrayByAddingObject:busCubeMen];
            [self->_sectionTitles addObject:title];
            
            
            [self.tableView reloadData];
        }
    });
}


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

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

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *dust = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self.class) forIndexPath:indexPath];
    
    NSString *key;
    id value;
    NSInteger bedWaitIndex = indexPath.section;
    key = _longerDeclined[bedWaitIndex][indexPath.row];
    value = _intentExpandingShakeInitialDominant[bedWaitIndex][key];
    BOOL sonBasic = [value isKindOfClass:[NSDictionary class]] || [value isKindOfClass:[NSArray class]];
    dust.backgroundColor = [UIColor clearColor];
    
    
    for (UIView *teamCan in dust.contentView.subviews) {
        [teamCan removeFromSuperview];
    }
    
    
    UILabel *tabLabel = [[UILabel alloc] init];
    tabLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightMedium];
    tabLabel.textColor = [UIColor darkGrayColor];
    tabLabel.text = key;
    tabLabel.numberOfLines = 0;
    [dust.contentView addSubview:tabLabel];
    
    
    UILabel *guideLabel = [[UILabel alloc] init];
    guideLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightRegular];
    guideLabel.textColor = [UIColor blackColor];
    guideLabel.numberOfLines = 0;
    guideLabel.textAlignment = NSTextAlignmentRight;
    [dust.contentView addSubview:guideLabel];
    
    
    [tabLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(dust.contentView).offset(SubBondFour.nodeFourteen.herQuitTight);
        make.top.equalTo(dust.contentView).offset(SubBondFour.nodeFourteen.potassiumTop);
        make.bottom.equalTo(dust.contentView).offset(-SubBondFour.nodeFourteen.potassiumTop);
        make.width.equalTo(dust.contentView.mas_width).multipliedBy(sonBasic?SubBondFour.nodeFourteen.briefCostTip:SubBondFour.nodeFourteen.pinAskSnapOut);
    }];
    
    [guideLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(dust.contentView).offset(-SubBondFour.nodeFourteen.herQuitTight);
        make.top.equalTo(dust.contentView).offset(SubBondFour.nodeFourteen.potassiumTop);
        make.bottom.equalTo(dust.contentView).offset(-SubBondFour.nodeFourteen.potassiumTop);
        make.left.equalTo(tabLabel.mas_right).offset(SubBondFour.nodeFourteen.potassiumTop);
    }];
    
    
    if (sonBasic) {
        dust.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    } else {
        guideLabel.text = [value description];
        dust.accessoryType = UITableViewCellAccessoryNone;
    }
    
    return dust;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    id value;
    NSString *key;
    
    NSInteger bedWaitIndex = indexPath.section;
    key = _longerDeclined[bedWaitIndex][indexPath.row];
    value = _intentExpandingShakeInitialDominant[bedWaitIndex][key];
    
    
    if ([value isKindOfClass:[NSDictionary class]]) {
        [self shelfInferDictionary:value withTitle:key];
    } else if ([value isKindOfClass:[NSArray class]]) {
        [self nothingJobArray:value withTitle:key];
    } else {
        
        UIPasteboard *moodWeekly = [UIPasteboard generalPasteboard];
        [moodWeekly setString:[value description]];
        [WasToast pickAnd:SubBondFour.nodeFourteen.greaterPlayUnpluggedPreciseUrgentLossy];
    }
}


- (void)shelfInferDictionary:(NSDictionary *)star withTitle:(NSString *)title {
    KinCharTwoViewController *ligature = [[KinCharTwoViewController alloc] init];
    [self.navigationController pushViewController:ligature animated:NO];
    [ligature heavyIllWhiteInfo:star withTitle:title];
}

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

@end
