






#import "LateTheHasViewController.h"
#import "DegreeNearConfig.h"
#import "NSObject+AllModel.h"
#import "UIColor+RetColor.h"
#import "KeyToast.h"

@interface LateTheHasViewController ()<UITableViewDataSource, UITableViewDelegate>

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

@end

@implementation LateTheHasViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    _directionSeekMountedAssetAll = [NSMutableArray array];
    _rollDogHowGram = @[];
    _sectionTitles = [NSMutableArray array];
    
    [self idleStaticView];
}

- (void)viewWillAppear:(BOOL)animated {
    
    UIEdgeInsets outScanner = [[ZoneAngleManager shared] retGigabytesWindow].safeAreaInsets;
    
    outScanner.top    += 10;
    outScanner.left   += 10;
    outScanner.bottom += 10;
    outScanner.right  += 10;

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


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


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

- (void)soundCapExistInfo:(NSDictionary *)info withTitle:(NSString *)title {
    if (!info || ![info isKindOfClass:[NSDictionary class]]) {
        return;
    }
    
    
    dispatch_async(dispatch_get_main_queue(), ^{
        @synchronized (self) {
            
            [self->_directionSeekMountedAssetAll addObject:[info copy]];
            NSArray *hisScrolls = [self hierarchyOuterDictionary:info];
            self->_rollDogHowGram = [self->_rollDogHowGram arrayByAddingObject:hisScrolls];
            [self->_sectionTitles addObject:title];
            
            
            [self.tableView reloadData];
        }
    });
}


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

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

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *trad = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self.class) forIndexPath:indexPath];
    
    NSString *key;
    id value;
    NSInteger wordDogIndex = indexPath.section;
    key = _rollDogHowGram[wordDogIndex][indexPath.row];
    value = _directionSeekMountedAssetAll[wordDogIndex][key];
    BOOL centrals = [value isKindOfClass:[NSDictionary class]] || [value isKindOfClass:[NSArray class]];
    trad.backgroundColor = [UIColor clearColor];
    
    
    for (UIView *bitPick in trad.contentView.subviews) {
        [bitPick removeFromSuperview];
    }
    
    
    UILabel *rowLabel = [[UILabel alloc] init];
    rowLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightMedium];
    rowLabel.textColor = [UIColor darkGrayColor];
    rowLabel.text = key;
    rowLabel.numberOfLines = 0;
    [trad.contentView addSubview:rowLabel];
    
    
    UILabel *chunkLabel = [[UILabel alloc] init];
    chunkLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightRegular];
    chunkLabel.textColor = [UIColor blackColor];
    chunkLabel.numberOfLines = 0;
    chunkLabel.textAlignment = NSTextAlignmentRight;
    [trad.contentView addSubview:chunkLabel];
    
    
    [rowLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(trad.contentView).offset(ClaimMaxBig.applierPatch.deferringOpt);
        make.top.equalTo(trad.contentView).offset(ClaimMaxBig.applierPatch.turnHeadline);
        make.bottom.equalTo(trad.contentView).offset(-ClaimMaxBig.applierPatch.turnHeadline);
        make.width.equalTo(trad.contentView.mas_width).multipliedBy(centrals?ClaimMaxBig.applierPatch.tabFloatLive:ClaimMaxBig.applierPatch.beginBoldHave);
    }];
    
    [chunkLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(trad.contentView).offset(-ClaimMaxBig.applierPatch.deferringOpt);
        make.top.equalTo(trad.contentView).offset(ClaimMaxBig.applierPatch.turnHeadline);
        make.bottom.equalTo(trad.contentView).offset(-ClaimMaxBig.applierPatch.turnHeadline);
        make.left.equalTo(rowLabel.mas_right).offset(ClaimMaxBig.applierPatch.turnHeadline);
    }];
    
    
    if (centrals) {
        trad.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    } else {
        chunkLabel.text = [value description];
        trad.accessoryType = UITableViewCellAccessoryNone;
    }
    
    return trad;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    id value;
    NSString *key;
    
    NSInteger wordDogIndex = indexPath.section;
    key = _rollDogHowGram[wordDogIndex][indexPath.row];
    value = _directionSeekMountedAssetAll[wordDogIndex][key];
    
    
    if ([value isKindOfClass:[NSDictionary class]]) {
        [self tryFlushedDictionary:value withTitle:key];
    } else if ([value isKindOfClass:[NSArray class]]) {
        [self outFocusesArray:value withTitle:key];
    } else {
        
        UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
        [pasteboard setString:[value description]];
        [KeyToast manyTop:ClaimMaxBig.applierPatch.operandMegahertzOutsideObjectSlashLittle];
    }
}


- (void)tryFlushedDictionary:(NSDictionary *)site withTitle:(NSString *)title {
    LateTheHasViewController *absolute = [[LateTheHasViewController alloc] init];
    [self.navigationController pushViewController:absolute animated:NO];
    [absolute soundCapExistInfo:site withTitle:title];
}

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

@end
