






#import "HowTrapHowViewController.h"
#import "CountPulseConfig.h"
#import "NSObject+PopModel.h"
#import "UIColor+PenColor.h"
#import "EggToast.h"

@interface HowTrapHowViewController ()<UITableViewDataSource, UITableViewDelegate>

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

@end

@implementation HowTrapHowViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    _stampShotHandlerStriationNative = [NSMutableArray array];
    _youOneLegalGet = @[];
    _sectionTitles = [NSMutableArray array];
    
    [self columnWideView];
}

- (void)viewWillAppear:(BOOL)animated {
    
    UIEdgeInsets orangeOnly = [[BitmapWaxManager shared] freezingThinWindow].safeAreaInsets;
    
    orangeOnly.top    += 10;
    orangeOnly.left   += 10;
    orangeOnly.bottom += 10;
    orangeOnly.right  += 10;

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


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


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

- (void)caretDeepThatInfo:(NSDictionary *)info withTitle:(NSString *)title {
    if (!info || ![info isKindOfClass:[NSDictionary class]]) {
        return;
    }
    
    
    dispatch_async(dispatch_get_main_queue(), ^{
        @synchronized (self) {
            
            [self->_stampShotHandlerStriationNative addObject:[info copy]];
            NSArray *acceptLogo = [self actionKeysMileDictionary:info];
            self->_youOneLegalGet = [self->_youOneLegalGet arrayByAddingObject:acceptLogo];
            [self->_sectionTitles addObject:title];
            
            
            [self.tableView reloadData];
        }
    });
}


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

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

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *trap = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self.class) forIndexPath:indexPath];
    
    NSString *key;
    id value;
    NSInteger sectionIndex = indexPath.section;
    key = _youOneLegalGet[sectionIndex][indexPath.row];
    value = _stampShotHandlerStriationNative[sectionIndex][key];
    BOOL oldDelay = [value isKindOfClass:[NSDictionary class]] || [value isKindOfClass:[NSArray class]];
    trap.backgroundColor = [UIColor clearColor];
    
    
    for (UIView *defines in trap.contentView.subviews) {
        [defines removeFromSuperview];
    }
    
    
    UILabel *anyLabel = [[UILabel alloc] init];
    anyLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightMedium];
    anyLabel.textColor = [UIColor darkGrayColor];
    anyLabel.text = key;
    anyLabel.numberOfLines = 0;
    [trap.contentView addSubview:anyLabel];
    
    
    UILabel *chestLabel = [[UILabel alloc] init];
    chestLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightRegular];
    chestLabel.textColor = [UIColor blackColor];
    chestLabel.numberOfLines = 0;
    chestLabel.textAlignment = NSTextAlignmentRight;
    [trap.contentView addSubview:chestLabel];
    
    
    [anyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(trap.contentView).offset(MillLiftIll.hintLegalHue.unitLowerGet);
        make.top.equalTo(trap.contentView).offset(MillLiftIll.hintLegalHue.darkenHockey);
        make.bottom.equalTo(trap.contentView).offset(-MillLiftIll.hintLegalHue.darkenHockey);
        make.width.equalTo(trap.contentView.mas_width).multipliedBy(oldDelay?MillLiftIll.hintLegalHue.vowelDrumIcy:MillLiftIll.hintLegalHue.bagHowPanPass);
    }];
    
    [chestLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(trap.contentView).offset(-MillLiftIll.hintLegalHue.unitLowerGet);
        make.top.equalTo(trap.contentView).offset(MillLiftIll.hintLegalHue.darkenHockey);
        make.bottom.equalTo(trap.contentView).offset(-MillLiftIll.hintLegalHue.darkenHockey);
        make.left.equalTo(anyLabel.mas_right).offset(MillLiftIll.hintLegalHue.darkenHockey);
    }];
    
    
    if (oldDelay) {
        trap.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    } else {
        chestLabel.text = [value description];
        trap.accessoryType = UITableViewCellAccessoryNone;
    }
    
    return trap;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    id value;
    NSString *key;
    
    NSInteger sectionIndex = indexPath.section;
    key = _youOneLegalGet[sectionIndex][indexPath.row];
    value = _stampShotHandlerStriationNative[sectionIndex][key];
    
    
    if ([value isKindOfClass:[NSDictionary class]]) {
        [self notGestureDictionary:value withTitle:key];
    } else if ([value isKindOfClass:[NSArray class]]) {
        [self rankOutputArray:value withTitle:key];
    } else {
        
        UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
        [pasteboard setString:[value description]];
        [EggToast fixLoop:MillLiftIll.hintLegalHue.softballPascalAnchorsClimbingBloodYahoo];
    }
}


- (void)notGestureDictionary:(NSDictionary *)sink withTitle:(NSString *)title {
    HowTrapHowViewController *cacheBed = [[HowTrapHowViewController alloc] init];
    [self.navigationController pushViewController:cacheBed animated:NO];
    [cacheBed caretDeepThatInfo:sink withTitle:title];
}

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

@end
