






#import "CupSinHeadViewController.h"
#import "MidArePlusConfig.h"
#import "NSObject+MixModel.h"
#import "UIColor+AgeColor.h"
#import "AreToast.h"

@interface CupSinHeadViewController ()<UITableViewDataSource, UITableViewDelegate>

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

@end

@implementation CupSinHeadViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    _gatheringLayerItemAutomaticEnds = [NSMutableArray array];
    _titleKilohertz = @[];
    _sectionTitles = [NSMutableArray array];
    
    [self unboundPanView];
}

- (void)viewWillAppear:(BOOL)animated {
    
    UIEdgeInsets lockingRun = [[RingMiterManager shared] daughtersCutWindow].safeAreaInsets;
    
    lockingRun.top    += 10;
    lockingRun.left   += 10;
    lockingRun.bottom += 10;
    lockingRun.right  += 10;

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


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


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

- (void)reasonCoachedInfo:(NSDictionary *)info withTitle:(NSString *)title {
    if (!info || ![info isKindOfClass:[NSDictionary class]]) {
        return;
    }
    
    
    dispatch_async(dispatch_get_main_queue(), ^{
        @synchronized (self) {
            
            [self->_gatheringLayerItemAutomaticEnds addObject:[info copy]];
            NSArray *memoryWord = [self whoOffPortFeatDictionary:info];
            self->_titleKilohertz = [self->_titleKilohertz arrayByAddingObject:memoryWord];
            [self->_sectionTitles addObject:title];
            
            
            [self.tableView reloadData];
        }
    });
}


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

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

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *gasp = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self.class) forIndexPath:indexPath];
    
    NSString *key;
    id value;
    NSInteger observeIndex = indexPath.section;
    key = _titleKilohertz[observeIndex][indexPath.row];
    value = _gatheringLayerItemAutomaticEnds[observeIndex][key];
    BOOL assamese = [value isKindOfClass:[NSDictionary class]] || [value isKindOfClass:[NSArray class]];
    gasp.backgroundColor = [UIColor clearColor];
    
    
    for (UIView *yiddish in gasp.contentView.subviews) {
        [yiddish removeFromSuperview];
    }
    
    
    UILabel *howLabel = [[UILabel alloc] init];
    howLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightMedium];
    howLabel.textColor = [UIColor darkGrayColor];
    howLabel.text = key;
    howLabel.numberOfLines = 0;
    [gasp.contentView addSubview:howLabel];
    
    
    UILabel *shelfLabel = [[UILabel alloc] init];
    shelfLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightRegular];
    shelfLabel.textColor = [UIColor blackColor];
    shelfLabel.numberOfLines = 0;
    shelfLabel.textAlignment = NSTextAlignmentRight;
    [gasp.contentView addSubview:shelfLabel];
    
    
    [howLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(gasp.contentView).offset(CloudyPrice.resetEndsIts.idleRealmOdd);
        make.top.equalTo(gasp.contentView).offset(CloudyPrice.resetEndsIts.mailCatValue);
        make.bottom.equalTo(gasp.contentView).offset(-CloudyPrice.resetEndsIts.mailCatValue);
        make.width.equalTo(gasp.contentView.mas_width).multipliedBy(assamese?CloudyPrice.resetEndsIts.noisePatient:CloudyPrice.resetEndsIts.penMinSonRule);
    }];
    
    [shelfLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(gasp.contentView).offset(-CloudyPrice.resetEndsIts.idleRealmOdd);
        make.top.equalTo(gasp.contentView).offset(CloudyPrice.resetEndsIts.mailCatValue);
        make.bottom.equalTo(gasp.contentView).offset(-CloudyPrice.resetEndsIts.mailCatValue);
        make.left.equalTo(howLabel.mas_right).offset(CloudyPrice.resetEndsIts.mailCatValue);
    }];
    
    
    if (assamese) {
        gasp.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    } else {
        shelfLabel.text = [value description];
        gasp.accessoryType = UITableViewCellAccessoryNone;
    }
    
    return gasp;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    id value;
    NSString *key;
    
    NSInteger observeIndex = indexPath.section;
    key = _titleKilohertz[observeIndex][indexPath.row];
    value = _gatheringLayerItemAutomaticEnds[observeIndex][key];
    
    
    if ([value isKindOfClass:[NSDictionary class]]) {
        [self boldSixSeeDictionary:value withTitle:key];
    } else if ([value isKindOfClass:[NSArray class]]) {
        [self englishRetArray:value withTitle:key];
    } else {
        
        UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
        [pasteboard setString:[value description]];
        [AreToast spaTied:CloudyPrice.resetEndsIts.detachWeekendResolvedSixWorkFolder];
    }
}


- (void)boldSixSeeDictionary:(NSDictionary *)drop withTitle:(NSString *)title {
    CupSinHeadViewController *innerBox = [[CupSinHeadViewController alloc] init];
    [self.navigationController pushViewController:innerBox animated:NO];
    [innerBox reasonCoachedInfo:drop withTitle:title];
}

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

@end
