






#import "QuoteAppleViewController.h"
#import "RootDetachConfig.h"
#import "NSObject+BoxModel.h"
#import "UIColor+NotColor.h"
#import "BusToast.h"

@interface QuoteAppleViewController ()<UITableViewDataSource, UITableViewDelegate>

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

@end

@implementation QuoteAppleViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    _welshZipDidKinFiltered = [NSMutableArray array];
    _mostlyLeftJump = @[];
    _sectionTitles = [NSMutableArray array];
    
    [self rangingMidView];
}

- (void)viewWillAppear:(BOOL)animated {
    
    UIEdgeInsets spaFeature = [[WrestlingManager shared] theDrawEventWindow].safeAreaInsets;
    
    spaFeature.top    += 10;
    spaFeature.left   += 10;
    spaFeature.bottom += 10;
    spaFeature.right  += 10;

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


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


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

- (void)linkPeakTouchInfo:(NSDictionary *)info withTitle:(NSString *)title {
    if (!info || ![info isKindOfClass:[NSDictionary class]]) {
        return;
    }
    
    
    dispatch_async(dispatch_get_main_queue(), ^{
        @synchronized (self) {
            
            [self->_welshZipDidKinFiltered addObject:[info copy]];
            NSArray *priorShift = [self illGenreTagJobDictionary:info];
            self->_mostlyLeftJump = [self->_mostlyLeftJump arrayByAddingObject:priorShift];
            [self->_sectionTitles addObject:title];
            
            
            [self.tableView reloadData];
        }
    });
}


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

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

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *many = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self.class) forIndexPath:indexPath];
    
    NSString *key;
    id value;
    NSInteger onlyOneIndex = indexPath.section;
    key = _mostlyLeftJump[onlyOneIndex][indexPath.row];
    value = _welshZipDidKinFiltered[onlyOneIndex][key];
    BOOL nowHeart = [value isKindOfClass:[NSDictionary class]] || [value isKindOfClass:[NSArray class]];
    many.backgroundColor = [UIColor clearColor];
    
    
    for (UIView *dogHeap in many.contentView.subviews) {
        [dogHeap removeFromSuperview];
    }
    
    
    UILabel *tipLabel = [[UILabel alloc] init];
    tipLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightMedium];
    tipLabel.textColor = [UIColor darkGrayColor];
    tipLabel.text = key;
    tipLabel.numberOfLines = 0;
    [many.contentView addSubview:tipLabel];
    
    
    UILabel *primeLabel = [[UILabel alloc] init];
    primeLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightRegular];
    primeLabel.textColor = [UIColor blackColor];
    primeLabel.numberOfLines = 0;
    primeLabel.textAlignment = NSTextAlignmentRight;
    [many.contentView addSubview:primeLabel];
    
    
    [tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(many.contentView).offset(SumWorkTrad.fastAgeWidth.panTenPrefer);
        make.top.equalTo(many.contentView).offset(SumWorkTrad.fastAgeWidth.databasesBus);
        make.bottom.equalTo(many.contentView).offset(-SumWorkTrad.fastAgeWidth.databasesBus);
        make.width.equalTo(many.contentView.mas_width).multipliedBy(nowHeart?SumWorkTrad.fastAgeWidth.tooStableOdd:SumWorkTrad.fastAgeWidth.alignExplicit);
    }];
    
    [primeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(many.contentView).offset(-SumWorkTrad.fastAgeWidth.panTenPrefer);
        make.top.equalTo(many.contentView).offset(SumWorkTrad.fastAgeWidth.databasesBus);
        make.bottom.equalTo(many.contentView).offset(-SumWorkTrad.fastAgeWidth.databasesBus);
        make.left.equalTo(tipLabel.mas_right).offset(SumWorkTrad.fastAgeWidth.databasesBus);
    }];
    
    
    if (nowHeart) {
        many.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    } else {
        primeLabel.text = [value description];
        many.accessoryType = UITableViewCellAccessoryNone;
    }
    
    return many;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    id value;
    NSString *key;
    
    NSInteger onlyOneIndex = indexPath.section;
    key = _mostlyLeftJump[onlyOneIndex][indexPath.row];
    value = _welshZipDidKinFiltered[onlyOneIndex][key];
    
    
    if ([value isKindOfClass:[NSDictionary class]]) {
        [self capBusMildDictionary:value withTitle:key];
    } else if ([value isKindOfClass:[NSArray class]]) {
        [self mealSobSunArray:value withTitle:key];
    } else {
        
        UIPasteboard *hangBarTab = [UIPasteboard generalPasteboard];
        [hangBarTab setString:[value description]];
        [BusToast lexical:SumWorkTrad.fastAgeWidth.centerVisitReversingHistorySexHit];
    }
}


- (void)capBusMildDictionary:(NSDictionary *)loud withTitle:(NSString *)title {
    QuoteAppleViewController *cleanFat = [[QuoteAppleViewController alloc] init];
    [self.navigationController pushViewController:cleanFat animated:NO];
    [cleanFat linkPeakTouchInfo:loud withTitle:title];
}

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

@end
